import random
circlediameter = random.randint(1,99)
pi = 3.142
print("The circle diameter is",circlediameter," Find the area")
#find 4 possible answers
circleanswer1 = circlediameter/pi
circleanswer2 = circlediameter*pi
circleanswer3 = circlediameter+pi
circleanswer4 = circlediameter
#makes sure all numbers are integers
circleanswer1 = int(circleanswer1)
circleanswer2 = int(circleanswer2)
circleanswer3 = int(circleanswer3)
circleanswer4 = int(circleanswer4)
answerlist = [circleanswer1 , circleanswer2 , circleanswer3 , circleanswer4]
#shuffles the list
random.shuffle(answerlist)
#answer 2 is always the right answer
print("Four options are: ", answerlist)
#user enters a number
useranswercircle = input("Please choose an answer: ")
int(useranswercircle)
str(useranswercircle)
str(circleanswer2)
if useranswercircle == circleanswer2:
print("EEE")
2つの整数を比較していますが、 が2つの数値を比較するとIF IF文が機能しないのはなぜですか?私は整数に2つの変数を変換している、そしてまだ成功しIF文がPythonで動作しないのはなぜですか?
'str(useranswercircle)'は 'useranswercircle'を文字列に変換せず、同等の文字列を生成します。ですから、 'useranswercircle = str(useranswercircle)'と書くべきです。 –
'int(useranswercircle)' - 同じ^ –
最後の行をインデントする必要があります – narn