0
Why this script doesn't give an output?
from math import pi def area(r): a=float(pi*float(r)*float(r)) return a x=input('enter the radius : ') y=input('enter the decimal place(1 to 5): ') z=area(x) if y==1: print('area of circle is ') w=round(z,1) print(w) if y==2: print('area of circle is ') w=round(z,2) print(w) if y==3: print('area of circle is ') w=round(z,3) print(w) if y==4: print('area of circle is ') w=round(z,4) print(w) if y==5: print('area of circle is ') w=round(z,5) print(w)
3 ответов
+ 2
y=int(input('enter the decimal place(1 to 5): '))
+ 4
Because y is a string so it fails to match your integers
+ 4
You can simplify the printing part by checking validity of the decimal places input with "if" as follows:
z=area(x)
if y in range(1, 6):
print('Area of circle is: ', round(z, y))
else:
print('You entered invalid decimal places')
Hth, cmiiw