Question

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...

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
Write the following ANNA assembly language programs. 1.HighestnumberWrite an ANNA assembly program (high.ac) that will continuously...
Write the following ANNA assembly language programs. 1.HighestnumberWrite an ANNA assembly program (high.ac) that will continuously prompt the user for numbers. When the user enters a negative number, print the highest positive number entered by the user and exit the program. Print a zero if they did not enter any positive numbers. 2.DivisionWrite an ANNA assembly program (div.ac) that divides two positive numbers that come from user input and returns both the quotient and the remainder. For example, if the...
Description The word bank system maintains all words in a text file named words.txt. Each line...
Description The word bank system maintains all words in a text file named words.txt. Each line in the text file stores a word while all words are kept in an ascending order. You may assume that the word length is less than 20. The system should support the following three functions: Word lookup: to check whether a given word exists in the word bank. Word insertion: to insert a new word into the word bank. No insertion should be made...
Part 1 Write a program that reads a line of input and display the characters between...
Part 1 Write a program that reads a line of input and display the characters between the first two '*' characters. If no two '*' occur, the program should display a message about not finding two * characters. For example, if the user enters: 1abc*D2Efg_#!*345Higkl*mn+op*qr the program should display the following: D2Efg_#! 1) Name your program stars.c. 2) Assume input is no more than 1000 characters. 3) String library functions are NOT allowed in this program. 4) To read a...
C++ See the provided specification files. Complete the implementation for each as a separate file. void...
C++ See the provided specification files. Complete the implementation for each as a separate file. void seen(std::string); If there is already a Word object in the Words list, then the number of occurrences for this word is incremented. If there is no Word object for this word already, create a new word object with occurrence =1, and insert this object into the list of Word objects. std::string getNextWord(); Returns the next word of the list and sets the currentItem pointer...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT