Python Practice Program 1

 Python Practice Program 1

Write a Python program which will keep adding a stream of numbers inputted by the user. The adding stops as soon as the user presses q key on keyboard.

Solution:

"""
Write a Python program which will keep adding a stream of numbers inputted by the user. The adding stops
as soon as the user presses q key on keyboard.
"""

sum = 0
while True:
userInput = input("Enter the item price or press q to quit: \n")
if (userInput!= 'q'):
sum = sum + int(userInput)
print(f"Ordered total so far {sum}")
else:
print(f"Your total bill amount is: {sum} \n" "Thanks for shopping with us")
break

Comments

Popular posts from this blog

Python Exercise 7 --- "Snake, Water, Gun"

Python Tutorial 38 --- "Self & __init__() (Constructors)(OOPS 3)"

Python Exercise 4 --- "Number Guessing Game"