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

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

Dog Age Converter Python always puts out 7

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...