Tuesday, 10 September 2013

Loop in Tip Calculator (Python)

Loop in Tip Calculator (Python)

So I'm making a tip calculator at the moment. The thing that I am stuck on
is where they can input the total amount of the cost. If they input an
integer I want it to break out of the loop but if they input something
else than an integer, I want it to stay in the loop and tell them to enter
an integer. Here is the code that I made for this portion. (Not all the
code)
Integer = range(1,10000)
while True:
while True:
Cost = raw_input("What was the cost? ")
Cost = int(Cost)
if Cost in Integer:
break
else:
pass
The spacing may not look correct but it is in the actual script. I still
don't know how to paste the code on here without having to add 4 spaces to
every line. Anyway, please let me know what you would do to complete the
task I need.

No comments:

Post a Comment