Reputation: 18645
Can someone please tell me how to get the code to ask for a value (say the user would enter 100.00) and put that number with it's 2 decimal points value for more functions later on, ie: multipling it, etc.
Thanks.
Upvotes: 0
Views: 2826
Reputation: 336108
Here's a start (for Python 3; for Python 2, use raw_input
instead of input
):
while True:
snum = input("Please enter a decimal number:")
try:
num = float(snum)
break
except ValueError:
print("This is not a valid decimal number!")
print("This number, rounded to two places, is: {:0.2f}".format(num))
Upvotes: 3