Python 我不知道';我不明白我的缩进为什么是错误的,当我输入答案时,它不会';除了一个错误,我什么也不输出
我正在使用PyScripter w/Python2.7.6运行它。我不明白为什么我的代码错了。有人能给我解释一下吗Python 我不知道';我不明白我的缩进为什么是错误的,当我输入答案时,它不会';除了一个错误,我什么也不输出,python,python-2.7,Python,Python 2.7,我正在使用PyScripter w/Python2.7.6运行它。我不明白为什么我的代码错了。有人能给我解释一下吗 def mainMenu(): answer = input("""Main Menu: Pythagoras Repeat Program Quit""") if answer == "Pythagoras": pythagoras() elif answer == "Repeat Program": mainMenu() elif answer == "Quit
def mainMenu():
answer = input("""Main Menu:
Pythagoras
Repeat Program
Quit""")
if answer == "Pythagoras":
pythagoras()
elif answer == "Repeat Program":
mainMenu()
elif answer == "Quit":
print("Program ended")
else:
mainMenu()
def pythagoras():
if answer == "Pythagoras":
aNotSquared = input("Input the value of A")
bNotSquared = input("Input the value of B")
aSquared = aNotSquared ** 2
bSquared = bNotSquared ** 2
valueC = aSquared + bSquared
print(valueC)
mainMenu()
不确定粘贴时是否出现缩进错误,但这也是需要解决的问题
- 在进入
函数之前,已经测试了Pythagoras()
,在函数内部检查if answer==“Pythagoras”
既不起作用也没有意义answer
- 无法对
需要将输入转换为字符串执行数学运算
int
- 在获取输入和打印结果时,为清晰起见,采用常规格式
- PEP-8
notsnake\u案例
CamelCase
from math import sqrt
def main_menu():
answer = input("""Main Menu:
Pythagoras
Repeat Program
Quit\nChoose option from above: """)
if answer == "Pythagoras":
pythagoras()
elif answer == "Repeat Program":
main_menu()
elif answer == "Quit":
print("Program ended")
else:
main_menu()
def pythagoras():
a_not_sqr = int(input("Input the value of A: "))
b_not_sqr = int(input("Input the value of B: "))
a_sqr = a_not_sqr ** 2
b_sqr = b_not_sqr ** 2
c_sqr = a_sqr + b_sqr
c_not_sqr = sqrt(c_sqr)
print(f'C Squared = {c_sqr}')
print(f'C = {round(c_not_sqr, 2)}')
main_menu()
你知道你需要一个缩进后的
def
?是的,很抱歉它没有出现在这里,我是这个网站的新手。请给出一个包括你的实际缩进;它在Python中很重要。阅读编辑帮助。谢谢,对不起,你太笨了。@sambarringer,你没有傻。你是新来的。这是不同的。请回答您的问题,重新粘贴代码,然后选择它并按Ctrl+K或单击{}
按钮缩进整个内容。这会保留你的缩进。
Main Menu:
Pythagoras
Repeat Program
Quit
Choose option from above: Pythagoras
Input the value of A: 10
Input the value of B: 10
C Squared = 200
C = 14.14