Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

DogAgePerYearInHuman = 7
HumanAge = input("What is your age?")
HumanAgeIfDog = DogAgePerYearInHuman * HumanAge

print(f"If you would be a dog you would be {DogAgePerYearInHuman} years old")

The output is always 7

question from:https://stackoverflow.com/questions/65942188/dog-age-converter-python-always-puts-out-7

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
245 views
Welcome To Ask or Share your Answers For Others

1 Answer

You're referring to the constant variable - DogAgePerYearInHuman - in your print statement. You need to replace that with the result of your product: HumanAgeIfDog.

Per Epsi95's comment, you also need to cast the input as integer (int(HumanAge)). Otherwise you'll get another unexpected result.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...