print "HEllo !!"
print "Today, I will calculate something for you !!"#introduces itself
inp = True
def start():
print "type 1 for ADDITION"
print "type 2 for SUBTRACTION"
print "type 3 for MULTIPLICATION" #asks for the kind of calculation
print "type 4 for DIVISION"
press=int(raw_input())
if press >= 5 :
print "Choose a NUMBER which is less than 5 and you will get the answer!!"
print "-------------------------------"
if press == 1:
print "Enter your first number"
num1 = input()
print "enter your second number" #adds
num2 = input()
result = num1 + num2
print " Your answer is "+ str(result)
print "-------------------------------"
if press == 2 :
print "Enter your first number"
num1 = input()
print "enter your second number" #subtracts
num2 = input()
result = num1 - num2
print " Your answer is "+ str(result)
print "-------------------------------"
if press == 3:
print "Enter your first number"
num1 = input()
print "enter your second number"
num2 = input() #multiplies
result = num1 * num2
print " Your answer is "+ str(result)
print "-------------------------------"
if press == 4:
print "Enter your first number"
num1 = input() #divides
print "enter your second number"
num2 = input()
result = num1/num2
print " Your answer is "+ str(result)
print "-------------------------------"
while inp :
start()
私は基本的なコマンドを使用してこの電卓を作成しました。唯一の問題は、誰かが1から4までの数字を要求する文字を入力すると、Pythonエラーが表示されることです。代わりに、Pythonが示す通常のエラーの代わりに、 "number only allowed"のようなカスタムメイドのエラーを出力できるようにしたいと考えています。数字やアルファベットが入るようにどのような変更を加えることができますか?誰かが手紙を入力すると、カスタムメイドのエラーが表示されますか? P.P. :私はあなたが何ができる「NUM1」または「num2の」python:手紙を取る方法?
P.S. : "num1"や "num2"ではなく、 "press"というvarを求めています。これは重複していません。同様の質問は、私が求めているものとあまりにも異なっています。もう一度やり直してください。 – Ashok