我使用的是python33,windows10和命令行。我想摆脱出现在' 7x3'周围的括号。等等。另外,有更简单的方法吗?我在while语句和if else语句下放置try和except语句时遇到了麻烦。此外,我希望有一种方法可以将doMath()调用用作bigMath()的参数。有没有办法结束shell中的无限循环而不关闭它?是否有人可以使用lambda函数关键字演示此程序?欢迎提出所有建议。
def doMath(Multiplication):
b = [21, 32, 36, 42, 45, 48, 49, 54, 56, 63 ]
n = [ '7 x 3' , ' 8 x 4 ', ' 9 x 4 ',' 7 x 6 ', ' 5 x 9 ',' 8 x 6 ' ,' 7 x 7 ', ' 9 x 6 ',' 7 x 8 ', ' 7 x 9 ' ]
x = 0
if Multiplication == b[x]:
print('correct')
else:
while Multiplication != b[x]:
print('Sorry that is an incorrect answer.')
try:
Multiplication=int(input ('Whats The Answer to (%s)? : ' % (n[x])))
except ValueError:
print('Numbers usally have no letters or special characters')
while x <9:
try:
Multiplication=int(input ('Whats The Answer to (%s)? : ' % (n[x+1])))
except ValueError:
print('Numbers usally have no letters or special characters')
if Multiplication == b[x+1]:
print('correct')
x = x+1
elif x == 10:
break
else:
print('Sorry that is an incorrect answer.')
def bigMath():
Multip = 'Pure Imagination'
while Multip != 21:
try:
Multip = int(input ('Whats The Answer to 7 x 3? '))
if Multip != 21:
print('Sorry that is an incorrect answer.')
except ValueError:
print('Numbers usally have no letters or special characters')
doMath(Multip)
bigMath()