我最近有一个覆盆子pi,我正在学习如何使用它来编写python代码。我也有一个覆盆子用户指南,我复制了计算器脚本,但它没有用,你能帮忙吗? 这是我的剧本;
username = raw_input("What is your name? ")
print ("Welcome to the program,",username
goAgain == 1
while goAgain == 1:
num1 = int(raw_input("type the first number"))
num2 = int(raw_input("type the second number"))
print num1, "added to", num2, "equals", num1 + num2
print num1, "minus", num2, "equals", num1 - num2
print num1, "multiplied by", num2, "equals", num1 * num2
goAgain = int(raw_input("Type 1 to enter more numbers, or any other number to quit: "))
答案 0 :(得分:1)
username = raw_input("What is your name?: ")
print ("Welcome to the program, ", username)
goAgain = 1 # <<< Equality check instead of assignment.
while goAgain == 1:
num1 = int(raw_input("type the first number: "))
num2 = int(raw_input("type the second number: "))
print num1, "added to", num2, "equals", num1 + num2
print num1, "minus", num2, "equals", num1 - num2
print num1, "multiplied by", num2, "equals", num1 * num2
goAgain = int(raw_input(
"Type 1 to enter more numbers, "
"or any other number to quit: "
))
PS:https://stackoverflow.com/editing-help - &gt;使用空格来正确缩进代码块
答案 1 :(得分:0)
您的代码具有左括号和等号(==
)而不是赋值符号(=
)。您的计划中还有一个IndentionError
。固定代码是这样的:
username = raw_input("What is your name? ")
print ("Welcome to the program,",username)
goAgain = 1
while goAgain == 1:
num1 = int(raw_input("type the first number"))
num2 = int(raw_input("type the second number"))
print num1, "added to", num2, "equals", num1 + num2
print num1, "minus", num2, "equals", num1 - num2
print num1, "multiplied by", num2, "equals", num1 * num2
goAgain = int(raw_input("Type 1 to enter more numbers, or any other number to quit: "))
这应该有效