SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Repetition Structures
Exercise:
Algorithm Workbench
Question:1 | ISBN:9780132576376 | Edition: 2

Question

Write a while loop that lets the user enter a number. The number should be multiplied by 10, and the result assigned to a variable named product. The loop should iterate as long as product is less than 100.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

#Initialized the variable name
product = 0

#while loop that lets the user enter a number
#The loop should iterate as long as product
#is less than 100.
while product < 100:
    number = float(input("Enter a number: "))
    #The number should be multiplied by 10, 
    #and the result assigned to a variable
    #named product 
    product = number * 10
#Display the product
print("The product is:", product)

Executed Output 1:

Enter a number: 4
Enter a number: 3
Enter a number: 5
Enter a number: 2
Enter a number: 33
The product is: 330.0

Executed Output 2:

Enter a number: 5
Enter a number: 2
Enter a number: 5
Enter a number: 2
Enter a number: 2
Enter a number: 2
Enter a number: 1
Enter a number: 1
Enter a number: 9
Enter a number: 10
The product is: 100.0

NOTE:  Prompt and read a number from the user. The value of 'product' exceeds or equals 100, the loop will stop iterating, and print the final value of product.

0 0

Discussions

Post the discussion to improve the above solution.