Question

In: Computer Science

Trace Each of the following programs on the paper provided. Program 1 User enters “cat”, “dog”,...

Trace Each of the following programs on the paper provided.

Program 1

User enters “cat”, “dog”, “chair”, “quit”

  1. full = ""
  2. count = 0
  3. si = str(input("word: "))
  4. while si != "quit":
  5.     full = full + si
  6.     count = count + 1
  7.     si = str(input("word: "))
  8. print(str(count) + " words")
  9. print("Full: " + str(full));

Line Number

it doesn't have to be this specific table...

Solutions

Expert Solution

Solution:

------------------------

Line 1:

Declaring variable full and assign empty string ("") to it.

Line 2:

Declaring variable count and assign 0 to it.

Line 3:

Asking user to enter word. convert that input word into string using str() function. and assign that word to variable si.

Assume that user enter cat. thus si = cat.

Line 4:

This loop will run untill user enter quit.

Here si !=quit condition true so loop body will execute.

Line 5 - Concatenate si to full . thus full will now contain cat

Line 6- Adding 1 to count . count become 1.

Line 7- Asking user to enter word. convert that input word into string using str() function. and assign that word to variable si.

Assume that user enter dog

Go back to Line 4:-

Here si !=quit condition true so loop body will execute.

Line 5 - Concatenate si to full . thus full will now contain catdog

Line 6- Adding 1 to count . count become 2.

Line 7- Asking user to enter word. convert that input word into string using str() function. and assign that word to variable si.

Assume that user enter chair

Go back to Line 4:-

Here si !=quit condition true so loop body will execute.

Line 5 - Concatenate si to full . thus full will now contain catdogchair

Line 6- Adding 1 to count . count become 3.

Line 7- Asking user to enter word. convert that input word into string using str() function. and assign that word to variable si.

assume that user enter quit

Go back to Line 4:-

Here si !=quit condition fails. thus loop body will not execute.

Line 8:

convert count to string by using str(count) . concatenate it with " words" and print it.

So it will print 3 words

Line 9:

convert full to string by using str(full) concatenate it with Full and print result.

So it will print Full: catdogchair


Related Solutions

Using an ArrayList, create a program which does the following: If the user enters quit, the...
Using an ArrayList, create a program which does the following: If the user enters quit, the program ends. If the user enters add followed by a string, program adds the string only to your ArrayList. If the user enters print, the program prints out the ArrayList contents. If the user enters size, the program prints out size of ArrayList, If the user enters remove followed by string, it removes all strings. interface example: **** Welcome to my List Program ****...
Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: Output the sum of all even numbers Output the sum of all odd numbers Output the count of all even numbers Output the count of all odd numbers You must use loops and numbers to do this. You must not use any arrays or vectors for this program.
You are writing a billing program that adds up the items a user enters. Your program...
You are writing a billing program that adds up the items a user enters. Your program should use a loop and prompt the user for the item number for each item in inventory to add to the bill. (You can ask the user for the number of items you will enter and use a counter controlled loop or a sentinel controlled loop that has a stop number. Either way is fine.) Here is the table of items in inventory: Item...
Write in Python and as 2 seperate programs Write a program that allows the user to...
Write in Python and as 2 seperate programs Write a program that allows the user to enter the total rainfall for each of 12 months into a LIST. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts. Data: January 7.9 inches February 10.1 inches March 3.4 inches April 6.7 inches May 8.9 inches June 9.4 inches July 5.9 inches August 4.1 inches September...
Design the logic for a program that has two parts: The user enters 15 numbers that...
Design the logic for a program that has two parts: The user enters 15 numbers that are stored into an array. The program uses the array to display the numbers back to the user in reverse order. You must use an array and one or more loops to get full credit. Can someone please help me figure this out?
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters a number, the program should print out the average of the last 3 numbers (or all numbers if 3 or less have been entered). I would like a detailed explanation so that a beginner level Java programmer could understand.
Write a program that will read user input, and do the following: 1. The user can...
Write a program that will read user input, and do the following: 1. The user can input letters [A-Z] as much as he wants (ignore case). 2. If the user input other than letters or two characters, stop the input process and start to print unduplicated sorted pairs such as the below examples: User input: A a e b d d D E a B 1 Output: AB AD AE BD BE DE User Input: a q w e dd...
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in...
Write a java program to convert Celsius degrees to Fahrenheit degrees the user enters degrees in Celsius and the program Coverts the input to Fahrenheit using the following formula T(°F) = T(°C) × 1.8 + 32 submit the source code Design output Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Design the logic for a program that has two parts. The user enters 15 test scores...
Design the logic for a program that has two parts. The user enters 15 test scores (values between 1-100) that are stored in an array. The program uses the array to compute and output the following statistics minimum maximum average Write this in pseudocode.
In the space provided below write a C++ program that asks the user to enter their...
In the space provided below write a C++ program that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen as well as onto a file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT