모두 안녕하세요! 내 목표는 male_cal 또는 fem_cal (암시 적)이 올바르게 인쇄되도록 나이를 반복하는 것입니다. 도와주세요! 많은 감사 -> Pythonidaer < - 나는 섹스를했던 것처럼잘못된 사용자 입력을 방지하기 위해 어떻게 루프합니까?
print("\nWelcome to the Daily Caloric Intake Calculator!")
나는 방법 루프 나이를 모른다.
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()
방정식에는 연령이 정수 여야합니다. 내가 어찌 할 수 있지?
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.""")
트릭을 할해야합니다. –
'{}'버튼을 사용하여 형식 코드를 수정하십시오. – furas
안녕하세요 @TerryJanReedy 의견을 보내 주셔서 감사합니다. 너뿐만 아니라 너에게 고마워. 나는 SO 및 Reddit에 대한 올바른 형식을 연구 중이므로 가장 간결한 방식으로 질문 할 수 있습니다. 또한 나는 전반적으로 나의 연구 기술을 연구하고 있으므로, 이미 응답 된 질문을 앞으로하지는 않습니다. 그러나 확실하지 않으면 내 질문에 대한 답을 얻는 편이 잘못 될 것입니다. happy holidays :) – Pythonidaer