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
Post a Comment