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)

12th Mar 2018, 3:34 AM
santosh hulbutti
santosh hulbutti - avatar
3 Respostas
+ 2
y=int(input('enter the decimal place(1 to 5): '))
12th Mar 2018, 4:45 AM
ChaoticDawg
ChaoticDawg - avatar
+ 4
Because y is a string so it fails to match your integers
12th Mar 2018, 4:42 AM
John Wells
John Wells - avatar
+ 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
12th Mar 2018, 6:15 AM
Ipang