我落後在以下幾個基本的腳本不應該問進入A和B的輸入邏輯類甚至給不相關的數字,是大於5簡單的計算器使用Python
#!/usr/bin/python
try :
print "Enter 1 for Addition "
print "Enter 2 for Subtraction"
print "Enter 3 for Multiplication"
print "Enter 4 for Divition"
class calc :
def Add (self, A, B):
print A + B
def Sub (self, A, B):
print A - B
def Mul (self, A, B):
print A * B
def Div (self, A, B):
print A/B
C = calc()
Input = int (raw_input ("Enter the choice:"))
A = int (raw_input ("Enter A:"))
B = int (raw_input ("Enter B:"))
if Input == 1:
C.Add (A,B)
elif Input == 2:
C.Sub (A,B)
elif Input == 3:
C.Mul (A,B)
elif Input == 4:
C.Div (A,B)
elif Input <= 5:
print "Its not avaliable try again"
exit()
except ValueError:
"The value is wrong"
如果您也許改變 「<=" to "> =」? –