Python 如何用大写字母阻止崩溃
有没有办法阻止此代码中的字符(字母):Python 如何用大写字母阻止崩溃,python,python-3.x,Python,Python 3.x,有没有办法阻止此代码中的字符(字母): x = '6' while x != '5': try: a = int(input('please enter what the first digit should be = ')) b = int(input('please enter what the second digit should be = ')) op = input('press 1 to add, 2 to subtract
x = '6'
while x != '5':
try:
a = int(input('please enter what the first digit should be = '))
b = int(input('please enter what the second digit should be = '))
op = input('press 1 to add, 2 to subtract, 3 to multiply or 4 to divide:')
if op == '1':
c = a + b
elif op == '2':
c = a - b
elif op == '3':
c = a * b
elif op == '4':
if b == 0:
c = 'cannot divide by 0'
else:
c = a / b
else:
c = 'a error'
print('Your answer is = ',c)
except ValueError:
print('Something went wrong! Please ensure you only entered numbers!!')
x = input('Press 5 to exit or 6 to continue: ')
if x != '5':
print('We continue :) ')
else:
print("Sad to see you go. Bye!")
我正在制作一个计算器应用程序,我想通过阻止所有字母来阻止崩溃。请在您的问题中包含完整的错误消息。可能重复您所说的阻止是什么意思?是否希望在键入字符(字母)后仍运行循环?还是要停止执行并引发异常?