Hallo alle! Mein Ziel ist es, das Alter zu durchlaufen, so dass Male_cal oder Fem_cal (implizit) korrekt gedruckt werden. Bitte helfen Sie! Viel Dank -> Pythonidaer < -Wie wiederhole ich, um falsche Benutzereingaben zu vermeiden?
print("\nWelcome to the Daily Caloric Intake Calculator!")
Ich weiß nicht, wie man Schleife Alter wie ich Sex haben.
age = int(input("\nHow old are you in years? "))
sex = input("\nAre you a male or a female? Enter 'male' or 'female'. ").lower()
if sex == "female" or sex == "f":
sex = "female"
elif sex == "male" or sex == "m":
sex = "male"
else:
sex = input("Sorry, there's only two choices: MALE or FEMALE. ").lower()
Die Gleichung erfordert Alter eine ganze Zahl sein. Wie kann ich narrensicher sein?
height = float(input("\nHow tall are you in inches? "))
metric_height = float(height * 2.54)
weight = float(input("\nWhat is your weight in pounds? "))
metric_weight = int(weight * 0.453592)
activity_level = float(input("""
Please select your activity level:
Sedentary (enter '1.2')
Moderatively Active (enter '1.3')
Active? (enter '1.4')
"""))
male_cal = 10 * metric_weight + 6.25 * metric_height - 5 * age - 161
fem_cal = 10 * metric_weight + 6.25 * metric_height - 5 * age + 5
if (sex == "male"):
carbs = int(male_cal * .45)
protein = int(male_cal * .20)
fats = int(male_cal * .35)
print("\nYour DCI should be: ", int(male_cal), "calories a day.")
print(f"""\nThat means getting:
{carbs} cals from carbs,
{fats} cals from fats, and
{protein} cals from protein.""")
elif (sex == "female"):
carbs = int(fem_cal * .45)
protein = int(fem_cal * .20)
fats = int(fem_cal * .35)
print("\nYour DCI should be: ", int(fem_cal), "calories a day.")
print(f"""\nThat means getting:
{carbs} cals from carbs,
{fats} cals from fats, and
{protein} cals from protein.""")
Es gibt mehrere ähnliche Fragen bereits mit vollständiger Antworten tun. –
Verwenden Sie den Button '{}', um den Formatcode zu korrigieren – furas
Hallo @TerryJanReedy Ich freue mich über Ihr Feedback. Danke dir auch furas. Ich forsche nach dem richtigen Format für SO und Reddit, damit ich eine Frage in der prägnantesten Form stellen kann. Ich arbeite auch insgesamt an meinen Forschungskompetenzen, damit ich in Zukunft keine Fragen stelle, die bereits beantwortet wurden. Allerdings werde ich irr auf der Seite der Beantwortung meiner Frage, wenn ich nicht sicher bin. Happy Holidays :) – Pythonidaer