+ 3
How to make my program accept FLOAT input???
when User Enters radius length in decimals, program doesnt accept it!!! #Programm for computing circle area! from math import pi r = input("Please Enter a circle's radius: ") if r.isdigit(): s = round((pi *(float(r)**2)),2) print ("The area of the circle with radius " + str(r) + " is: " + str(s)) else: print ("Please Enter the length of the radius (Use digits only)")
2 Respostas
+ 12
isdigit() checks if the string contains only digits, which means that decimal points are rejected.
Just handle possible exceptions via try blocks instead.
try:
r = float(input())
# the rest of your code here
except ValueError:
# handle bad input here
+ 6
Hatsy Rei Do we think alike or you stole my answer a day before I thought of it?
Anton Kuznetsov Hatsy's is the answer.