トップページ > プログラム > 2015年03月05日 > XfWaMqOT

書き込み順位&時間帯一覧

15 位/179 ID中時間01234567891011121314151617181920212223Total
書き込み数0000000000000200000000002



使用した名前一覧書き込んだスレッド一覧
Yuta@
YutaA
くだすれPython(超初心者用) その25©2ch.net

書き込みレス一覧

くだすれ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.


※このページは、『2ちゃんねる』の書き込みを基に自動生成したものです。オリジナルはリンク先の2ちゃんねるの書き込みです。
※このサイトでオリジナルの書き込みについては対応できません。
※何か問題のある場合はメールをしてください。対応します。