- くだすれPython(超初心者用) その25©2ch.net
702 :Yuta@[]:2015/03/05(木) 13:26:12.70 ID:XfWaMqOT - ただいまプログラム製作中で、num1 とnum2 にデータを入力させて、それらをoperatorに入力された
ものにしたがって計算する、というのをやっているのですが、うまくいきません。 どうしたらいいでしょうか。。 prompt='Input first number.\n' num1=input(prompt) #input the number1 if num1 == 0: print('Error') else: prompt2='Input operator\n' operator=input(prompt2) #If the number is zero, print Error. If not, input the operator if operator !="+": if operator !="-": if operator !="*": if operator !="/": print('Error')
| - くだすれPython(超初心者用) その25©2ch.net
703 :YutaA[]:2015/03/05(木) 13:27:21.79 ID:XfWaMqOT - #If the operator is not "+","-","*","/", print Error.
else: prompt2='Input second number.\n' num2=input(prompt2) #If not, input num2 if num2 == 0: print('Error') #If the number is zero, print Error. else: if operator=='+': print(num1+num2) elif operator=='-': print(num1-num2) elif operator=='*': print(num1*num2) else: print(num1/num2) #If the number isn't zero, calculate num1 and num2.
|
|