0

問題は解決しました。しかし、私のアカウントは新しいので、質問に答えることはできません。input() のインスタンスを raw_input() で変更すると機能するようです。正直なところ理由はわかりませんが、2 と 3 の違いに関係があるのか​​もしれません。

面積と円周を計算できるプログラムを作ることになっています。その部分はそれほど難しくありません。

ただし、メニューは機能していません。メニューの最初の部分は問題なく動作しますが、選択を行った後、本来あるべきものが印刷されません。

import math

print ("""
1) Calculate circumference
2) Calculate area
""")
ans = input("Enter 1, 2, or 0 to exit this program: ")
if ans == "1":
    diameter = float(input("Enter the diameter: "))
    if diameter > 0:
        circumference = (diameter*math.pi)
        print("The circumference is", circumference)
    else:
        print("Error: the diameter must be a positive number.")
if ans == "2":
    radius = float(input("Enter the radius: "))
    if radius > 0:
        area = ((radius**2)*math.pi)
        print("The area is", area)
    else:
        print("Error: the radius must be a postive number.")
if ans == "0":
    print("Thanks for hanging out with me!")
    quit()
4

4 に答える 4