我的代码:
import math
import sys
def addition():
one = int(input('What is your first number? '))
two = int(input('what is your second number? '))
print(one + two)
def Subtraction():
one = int(input('What is your first number ? '))
two = int(input('what is your second number? '))
print(one - two)
def Multiplication():
one = int(input('What is your first number ? '))
two = int(input('what is your second number? '))
print(one * two)
def Division():
one = int(input('What is your first number? '))
two = int(input('What is your first number? '))
print(one / two)
def Modulo():
one = int(input('What is your first number? '))
two = int(input('what is your second number? '))
print(one % two)
calc_run = True
while calc_run == True:
def calc_run():
op = input('Do you want to add,subtract,multiply,divide, modulo or quit. ')
if op == 'add':
addition()
elif op == 'subtract':
Subtraction()
elif op == 'multiply':
Multiplication()
elif op == 'divide':
Division()
elif op == 'modulo':
Modulo()
elif op == 'quit':
print("Thanks for using this app")
sys.exit
break
calc_run()
错误:
'break' outside loop
该代码在我尝试执行此操作时有效:
import math
import sys
def addition():
one = int(input('What is your first number? '))
two = int(input('what is your second number? '))
print(one + two)
def Subtraction():
one = int(input('What is your first number ? '))
two = int(input('what is your second number? '))
print(one - two)
def Multiplication():
one = int(input('What is your first number ? '))
two = int(input('what is your second number? '))
print(one * two)
def Division():
one = int(input('What is your first number? '))
two = int(input('What is your first number? '))
print(one / two)
def Modulo():
one = int(input('What is your first number? '))
two = int(input('what is your second number? '))
print(one % two)
calc_run = True
while True:
def calc_run():
op = input('Do you want to add,subtract,multiply,divide, modulo or quit. ')
if op == 'add':
addition()
elif op == 'subtract':
Subtraction()
elif op == 'multiply':
Multiplication()
elif op == 'divide':
Division()
elif op == 'modulo':
Modulo()
elif op == 'quit':
print("Thanks for using this app")
sys.exit
calc_run = False
calc_run()
答案 0 :(得分:0)
这按预期工作。
在Python 2.7上进行了测试。
import math
import sys
def addition():
one = int(input('What is your first number? '))
two = int(input('what is your second number? '))
print(one + two)
def Subtraction():
one = int(input('What is your first number ? '))
two = int(input('what is your second number? '))
print(one - two)
def Multiplication():
one = int(input('What is your first number ? '))
two = int(input('what is your second number? '))
print(one * two)
def Division():
one = int(input('What is your first number? '))
two = int(input('What is your first number? '))
print(one / two)
def Modulo():
one = int(input('What is your first number? '))
two = int(input('what is your second number? '))
print(one % two)
calc_run = True
while calc_run == True:
op = raw_input('Do you want to add,subtract,multiply,divide, modulo or quit. ')
if op == 'add':
addition()
elif op == 'subtract':
Subtraction()
elif op == 'multiply':
Multiplication()
elif op == 'divide':
Division()
elif op == 'modulo':
Modulo()
elif op == 'quit':
print("Thanks for using this app")
#sys.exit
break