私のコードで変数に問題があります。私はそれで「午後」と番号などの入力TOTAL_TIMEが、私はシェルで実行されていたこれらのコード行を示して 「彼は眠っている」、else文を取得するたびにPython - 浮動小数点変数は常に比較として最大値を返します
import re
name = raw_input("Input the Character's name: ")
name = name.lower()
season = raw_input("Input the season: ")
rainyday = raw_input("Is it a rainy day? ")
total_time = raw_input("What time is it?(Input as e.g 1.30 am")
non_decimal = re.compile(r'[^\d.]+')
timel = non_decimal.sub('', total_time)
float(timel)
print timel
#ALEX
if name == "alex":
if rainyday == "yes":
if "am" in total_time:
if time > 8.00:
print("He's in the entryway of his house until 1:00 PM")
else:
print("He's in his room until 8:00 AM")
print("!")
elif timel < 1:
print("He's in the entryway of his room until 1:00 PM")
print("y")
elif timel < 4.2:
print("He's leaving his room to go to the dog pen until 6:30 PM")
elif timel < 6.3:
print("He's at the dog pen until 6:30")
elif timel < 8.0:
print("He's in the entryway of his house until 8:00 P.M")
elif timel < 10.0:
print("He's standing by the dresser in his room")
else:
print("He's sleeping")
:ここに私のコードの一部であります私の問題:
>>> print timel
2
>>> timel < 3
False
>>> 2 < 3
True
>>> timel < 1000000000
False
timelは、それが定義されているにもかかわらず、常に他のすべてよりも大きくなっている未定義の数であるようです。私はこの問題の助けに大いに感謝します。
または変換する
timel = float(timel)
なければなりません – zvone