+ 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)")

13th May 2019, 11:50 PM
kuzantiv
kuzantiv - avatar
2 Antworten
+ 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
14th May 2019, 12:16 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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.
15th May 2019, 10:06 PM
Kainatic [Mostly Inactive Now]
Kainatic [Mostly Inactive Now] - avatar