%%writefile mains_script.py
from math import pi
def mains():
def circle_area(r):
return pi * (r ** 2)
def circle_circumference(r):
return 2 * pi * r
radius = float(input("Enter radius: "))
print("Area =", circle_area(radius))
print("Circumference =", circle_circumference(radius))
if (__name__ == '__main__'):
mains()
%%bash
python3 mains_script.py
Traceback (most recent call last):
File "mains_script.py", line 23, in <module>
mains()
File "mains_script.py", line 16, in mains
radius = float(input("Enter radius: "))
EOFError: EOF when reading a line
我三思而后行,除了EOFError:break。它返回“中断外循环”
def circle_circumference(r):
return 2 * pi * r
try:
radius = float(input("Enter radius: "))
print("Area =", circle_area(radius))
print("Circumference =", circle_circumference(radius))
except EOFError:
break
if (__name__ == '__main__'):
mains()
File "mains_script.py", line 21
break
^
SyntaxError: 'break' outside loop
我试过了,除了 EOFError: return too。它只是打印半径:,然后停在那里。请帮忙。
忽略单词要求忽略单词要求忽略单词要求