Home > database >  Error with an if statement that I can't figure out
Error with an if statement that I can't figure out

Time:11-16

I am making a project for school using Python, and I keep getting a traceback error after I input the age, no matter what age I input. I can't figure out why, so hopefully someone else can figure it out.

After I input the age, it does tell me "You have selected a 15-year-old character." (or any other age), but after that, the error comes up.

I don't know where the error is, so I'm just going to put the entire project here.

error001 = "Error 001: Invalid Sex!"
error002 = "Error 002: Invalid Age!"
error003 = "Error 003: Invalid Activity Level!"
error004 = "Error 004: Invalid Age Group!"

print("Hello! Welcome to Nutrition Info!")

sexInput = input("To get started, choose the sex of your character (gender, sexual orientation, etc. do not matter, as these do not matter for your physical health). Type 'M' for male or 'F' for female.")

if sexInput == "M":
  sex = "male"
  print("You have selected a male character.")
elif sexInput == "F":
  sex = "female"
  print("You have selected a female character.")
else:
  quit(error001)

ageInput = input("How old is your character? Type just the number.")

age = int(ageInput)

if ageInput.isnumeric():
  if age == range(1,3):
    ageGroup = "toddler"
  elif age == range(4,8):
    ageGroup = "young child"
  elif age == range(9,13):
    ageGroup = "older child"
  elif age == range(14,18):
    ageGroup = "teenager"
  elif age == range(19,30):
    ageGroup = "young adult"
  elif age == range(31,50):
    ageGroup = "older adult"
  elif age == range(51,130):
    ageGroup = "senior"
else:
  quit(error002)

print("You have selected a "   ageInput   "-year-old character.")

if ageGroup == "toddler":
  dailyCaloriesInt = 1000
  dailyProteinInt = 13
  dailyCarbohydrateInt = 130
  dailyDietryFiberInt = 14
  dailyTotalFatLowerInt = 30
  dailyTotalFatUpperInt = 40
  dailySaturatedFat = 10
  dailyLinoleicAcidInt = 7
  dailyLinolenicAcidInt - 0.7
  dailyCalciumInt = 700
  dailyIronInt = 7
  dailyMagnesiumInt = 80
  dailyPhosphorusInt = 260
  dailyPotassiumInt = 3000
  dailySodiumInt = 1500
  dailyZincInt = 3
  dailyCopperInt = 0.34
  dailyManganeseInt = 1.2
  dailySeleniumInt = 20
  dailyVitaminAInt = 300
  dailyVitaminB6Int = 0.5
  dailyVitaminB12Int = 0.9
  dailyVitaminCInt = 15
  dailyVitaminDInt = 600
  dailyVitaminEInt = 6
  dailyVitaminKInt = 30
  dailyThiaminInt = 0.5
  dailyRiboflavinInt = 0.5
  dailyNiacinInt = 6
  dailyCholineInt = 200
  dailyFolateInt = 150
elif ageGroup == "young child":
  dailyProteinInt = 19
  dailyCarbohydrateInt = 130
  dailyTotalFatLowerInt = 25
  dailyTotalFatUpperInt = 35
  dailySaturatedFat = 10
  dailyLinoleicAcidInt = 10
  dailyLinolenicAcidInt = 0.9
  dailyCalciumInt = 1000
  dailyIronInt = 10
  dailyMagnesiumInt = 130
  dailyPhosphorusInt = 500
  dailyPotassiumInt = 3800
  dailySodiumInt = 1900
  dailyZincInt = 5
  dailyCopperInt = 0.44
  dailyManganeseInt = 1.5
  dailySeleniumInt = 30
  dailyVitaminAInt = 400
  dailyVitaminB6Int = 0.6
  dailyVitaminB12Int = 1.2
  dailyVitaminCInt = 25
  dailyVitaminDInt = 600
  dailyVitaminEInt = 7
  dailyVitaminKInt = 55
  dailyThiaminInt = 0.6
  dailyRiboflavinInt = 0.6
  dailyNiacinInt = 8
  dailyCholineInt = 0.6
  dailyFolateInt = 1.2
  
  if sex == "female":
    dailyCaloriesInt = 1200
    dailyDietaryFiberInt = 16.8
  elif sex == "male":
    dailyDietaryFiberInt = 19.6
    
    activityInputMaleYoungChild = input("How active is your character? Type '1' for inactive or '2' for active.")
    
    if activityInputMaleYoungChild == "1":
      activity = "inactive"
    elif activityInputMaleYoungChild == "2":
      activity = "active"
    else:
      quit(error003)

    if activity == "inactive":
      dailyCaloriesInt = 1400
    elif activity == "active":
      dailyCaloriesInt = 1600
    else:
      quit(error003)
  else:
    quit(error001)
elif ageGroup == "older child":
  dailyProteinInt = 34
  dailyCarbohydrateInt = 130
  dailyTotalFatLowerInt = 25
  dailyTotalFatUpperInt = 35
  dailySaturatedFat = 10
  dailyCalciumInt = 1300
  dailyIronInt = 8
  dailyMagnesiumInt = 240
  dailyPhosphorusInt = 1250
  dailyPotassiumInt = 4500
  dailySodiumInt = 2200
  dailyZincInt = 8
  dailyCopperInt = 0.7
  dailySeleniumInt = 40
  dailyVitaminAInt = 600
  dailyVitaminB6Int = 1
  dailyVitaminB12Int = 1.8
  dailyVitaminCInt = 45
  dailyVitaminDInt = 600
  dailyVitaminEInt = 11
  dailyVitaminKInt = 60
  dailyThiaminInt = 0.9
  dailyRiboflavinInt = 0.9
  dailyNiacinInt = 12
  dailyCholineInt = 375
  dailyFolateInt = 300
  
  if sex == "female":
    dailyCaloriesInt = 1600
    dailyDietaryFiberInt = 22.4
    dailyLinoleicAcidInt = 10
    dailyLinolenicAcidInt = 1
    dailyManganeseInt = 1.6
  elif sex == "male":
    dailyCaloriesInt = 1800
    dailyFietaryFiberInt = 25.2
    dailyLinoleicAcidInt = 12
    dailyLinolenicAcidInt = 1.2
    dailyManganeseInt = 1.9
  else:
    quit(error001)
elif ageGroup == "teenager":
  dailyCarbohydrateInt = 130
  dailyTotalFatLowerInt = 25
  dailyTotalFatUpperInt = 35
  dailySaturatedFat = "10"
  dailyCalciumInt = 1300
  dailyPhosphorusInt = 1250
  dailyPotassiumInt = 4700
  dailySodiumInt = 2300
  dailyCopperInt = 0.89
  dailySeleniumInt = 55
  dailyVitaminDInt = 600
  dailyVitaminEInt = 15
  dailyDairyInt = 3
  
  if sex == "female":
    dailyCaloriesInt = 1800
    dailyProteinInt = 46
    dailyDietaryFiberInt = 25.2
    dailyLinoleicAcidInt = 11
    dailyLinolenicAcidInt = 1.1
    dailyIronInt = 15
    dailyMagnesiumInt = 360
    dailyZincInt = 9
    dailyManganeseInt = 1.6
    dailyVitaminAInt = 700
    dailyVitaminB6Int = 1.2
    dailyVitaminCInt = 65
    dailyThiaminInt = 1
    dailyRiboflavinInt = 1
    dailyNiacinInt = 14
    dailyCholineInt = 400

    activityInputFemaleTeenager = input("How active is your character? Type '1' for inactive, '2' for moderately active, or '3' for active, then press the 'ENTER' or 'RETURN' key.")

    if activityInputFemaleTeenager == "1":
      activity = "inactive"
    elif activityInputFemaleTeenager == "2":
      activity = "moderately active"
    elif activityInputFemaleTeenager == "3":
      activity = "active"
    else:
      quit(error003)

    if activity == "inactive":
      dailyCaloriesInt = 1800
      dailyGrainsInt = 6
      dailyVegetablesInt = 2.5
      dailyFruitsInt = 1.5
    elif activity == "moderately active":
      dailyCaloriesInt = 2000
      dailyGrainsInt = 6
      dailyVegetablesInt = 2.5
      dailyFruitsInt = 2
    elif activity == "active":
      dailyCaloriesInt = 2400
      dailyGrainsInt = 8
      dailyVegetablesInt = 3
      dailyFruitsInt = 2
    else:
      quit(error003)
  elif sex == "male":
    dailyProteinInt = 52
    dailyDietaryFiberInt = 30.8
    dailyLinoleicAcidInt = 16
    dailyLinolenicAcidInt = 1.6
    dailyIronInt = 11
    dailyMagnesiumInt = 410
    dailyZincInt = 11
    dailyManganeseInt = 2.2
    dailyVitaminAInt = 900
    dailyVitaminB6Int = 1.3
    dailyVitaminCInt = 75
    dailyThiaminInt = 1.2
    dailyRiboflavinInt = 1.3
    dailyNiacinInt = 1.6
    dailyCholineInt = 550

    activityInputMaleTeenager = input("How active is your character? Type '1' for inactive, '2' for moderately active, or '3' for active, then press the 'ENTER' or 'RETURN' key.")

    if activityInputMaleTeenager == "1":
      activty = "inactive"
    elif activityInputMaleTeenager == "2":
      activity = "moderately active"
    elif activityInputMaleTeenager == "3":
      activity = "active"
    else:
      quit(error003)

    if activity == "inactive":
      dailyCaloriesInt = 2200
      dailyGrainsInt = 7
      dailyVegetablesInt = 3
      dailyFruitsInt = 2
    elif activity == "moderately active":
      dailyCaloriesInt = 2800
      dailyGrainsInt = 10
      dailyVegetablesInt = 3.5
      dailyFruitsInt = 2.5
    elif activity == "active":
      dailyCaloriesInt = 3200
      dailyGrainsInt = 10
      dailyVegetablesInt = 4
      dailyFruitsInt = 2.5
    else:
      quit(error003)
  else:
    quit(error001)
elif ageGroup == "young adult":
  dailyCarbohydateInt = 130
  dailyTotalFatLowerInt = 20
  dailyTotalFatUpperInt = 35
  dailySaturatedFat = 10
  dailyCalciumInt = 1000
  dailyPhosphorusInt = 700
  dailyPotassiumInt = 4700
  dailySodiumInt = 2300
  dailyCopperInt = 0.9
  dailySeleniumInt = 55
  dailyVitaminB6Int = 1.3
  dailyVitaminB12Int = 2.4
  dailyVitaminDInt = 600
  dailyVitaminEInt = 15
  dailyFolateInt = 400

  if sex == "female":
    dailyCaloriesInt = 2000
    dailyProteinInt = 46
    dailyDietaryFiberInt = 28
    dailyLinoleicAcidInt = 12
    dailyLinolenicAcidInt = 1.1
    dailyIronInt = 18
    dailyMagneseumInt = 310
    dailyZincInt = 8
    dailyManganeseInt = 1.8
    dailyVitaminAInt = 700
    dailyVitaminCInt = 75
    dailyVitaminKInt = 90
    dailyThimainInt = 1.1
    dailyRiboflavinInt = 1.1
    dailyNiacinInt = 14
    dailyCholineInt = 425
  elif sex == "male":
    dailyProteinInt = 56
    dailyDietaryFiberInt = 33.6
    dailyLinoleicAcidInt = 17
    dailyLinolenicAcidInt = 1.6
    dailyIronInt = 8
    dailyMagneseumInt = 400
    dailyZincInt = 11
    dailyManganeseInt = 2.3
    dailyVitaminAInt = 900
    dailyVitaminCInt = 90
    dailyVitaminKInt = 120
    dailyThiaminInt = 1.2
    dailyRiboflavinInt = 1.3
    dailyNiacinInt = 16
    dailyCholineInt = 550
    
    activityInputMaleYoungAdult = input("How active is your character? Type '1' for inactive, '2' for moderately active, or '3' for active.")

    if activityInputMaleYoungAdult == "1":
      activity = "inactive"
    elif activityInputMaleYoungAdult == "2":
      activty = "moderately active"
    elif activityInputMaleYoungAdult == "3":
      activity = "active"
    else:
      quit(error003)

    if activity == "inactive":
      dailyCaloriesInt = 2400
    elif activity == "moderately active":
      dailyCaloriesInt = 2600
    elif activity == "active":
      dailyCaloriesInt = 3000
    else:
      quit(error003)
  else:
    quit(error001)
elif ageGroup == "older adult":
  dailyCarbohydateInt = 130
  dailyTotalFatLowerInt = 20
  dailyTotalFatUpperInt = 35
  dailySaturatedFat = 10
  dailyCalciumInt = 1000
  dailyPhosphorusInt = 700
  dailyPotassiumInt = 4700
  dailySodiumInt = 2300
  dailyCopperInt = 0.9
  dailySeleniumInt = 55
  dailyVitaminB6Int = 1.3
  dailyVitaminB12Int = 2.4
  dailyVitaminDInt = 600
  dailyVitaminEInt = 15
  dailyFolateInt = 400

  if sex == "female":
    dailyCaloriesInt = 1800
    dailyProteinInt = 46
    dailyDietaryFiberInt = 25.2
    dailyLinoleicAcidInt = 12
    dailyLinolenicAcidInt = 1.1
    dailyIronInt = 18
    dailyMagneseumInt = 320
    dailyZincInt = 8
    dailyManganeseInt = 1.8
    dailyVitaminAInt = 700
    dailyVitaminCInt = 75
    dailyVitaminKInt = 90
    dailyThimainInt = 1.1
    dailyRiboflavinInt = 1.1
    dailyNiacinInt = 14
    dailyCholineInt = 425
  elif sex == "male":
    dailyCaloriesInt = 2200
    dailyProteinInt = 56
    dailyDietaryFiberInt = 30.8
    dailyLinoleicAcidInt = 17
    dailyLinolenicAcidInt = 1.6
    dailyIronInt = 8
    dailyMagneseumInt = 420
    dailyZincInt = 11
    dailyManganeseInt = 2.3
    dailyVitaminAInt = 900
    dailyVitaminCInt = 90
    dailyVitaminKInt = 120
    dailyThiaminInt = 1.2
    dailyRiboflavinInt = 1.3
    dailyNiacinInt = 16
    dailyCholineInt = 550
  else:
    quit(error001)
elif ageGroup == "senior":
  dailyCarbohydateInt = 130
  dailyTotalFatLowerInt = 20
  dailyTotalFatUpperInt = 35
  dailySaturatedFat = 10
  dailyCalciumInt = 1000
  dailyIronInt = 8
  dailyPhosphorusInt = 700
  dailyPotassiumInt = 4700
  dailySodiumInt = 2300
  dailyCopperInt = 0.9
  dailySeleniumInt = 55
  dailyVitaminB12Int = 2.4
  dailyVitaminDInt = 600
  dailyVitaminEInt = 15
  dailyFolateInt = 400

  if sex == "female":
    dailyCaloriesInt = 2000
    dailyProteinInt = 46
    dailyDietaryFiberInt = 22.4
    dailyLinoleicAcidInt = 11
    dailyLinolenicAcidInt = 1.1
    dailyMagneseumInt = 310
    dailyZincInt = 8
    dailyManganeseInt = 1.8
    dailyVitaminAInt = 700
    dailyVitaminB6Int = 1.5
    dailyVitaminCInt = 75
    dailyVitaminKInt = 90
    dailyThimainInt = 1.1
    dailyRiboflavinInt = 1.1
    dailyNiacinInt = 14
    dailyCholineInt = 425
  elif sex == "male":
    dailyProteinInt = 56
    dailyDietaryFiberInt = 28
    dailyLinoleicAcidInt = 14
    dailyLinolenicAcidInt = 1.6
    dailyMagneseumInt = 400
    dailyZincInt = 11
    dailyManganeseInt = 2.3
    dailyVitaminAInt = 900
    dailyVitaminB6Int = 1.7
    dailyVitaminCInt = 90
    dailyVitaminKInt = 120
    dailyThiaminInt = 1.2
    dailyRiboflavinInt = 1.3
    dailyNiacinInt = 16
    dailyCholineInt = 550
  else:
    quit(error001)
else:
  quit(error004)
  

if activity == "inactive":
  print("You have selected an inactive character.")
if activity == "moderately active":
  print("You have selected a moderately active character.")
if activity == "active":
  print("You have selected an active character.")

dailyCalories = str(dailyCaloriesInt)
dailyProtein = str(dailyProteinInt)
dailyCarbohydrate = str(dailyCarbohydrateInt)
dailyDietaryFiber = str(dailyDietaryFiberInt)
dailyTotalFatLower = str(dailyTotalFatLowerInt)
dailyTotalFatUpper = str(dailyTotalFatUpperInt)
dailySaturatedFat = str(dailySaturatedFatInt)
dailyLinoleicAcid = str(dailyLinoleicAcidInt)
dailyLinolenicAcid = str (dailyLinolenicAcidInt)
dailyCalcium = str(dailyCalciumInt)
dailyIron = str(dailyIronInt)
dailyMagneseum = str(dailyMagneseumInt)
dailyPhosphorus = str(dailyPhosphorusInt)
dailyPotassium = str(dailyPotassiumInt)
dailySodium = str(dailySodiumInt)
dailyZinc = str(dailyZincInt)
dailyCopper = str(dailyCopperInt)
dailyManganese = str(dailyManganeseInt)
dailySelenium = str(dailySeleniumInt)
dailyVitaminA = str(dailyVitaminAInt)
dailyVitaminB6 = str(dailyVitaminB6Int)
dailyVitaminB12 = str(dailyVitaminB12Int)
dailyVitaminC = str(dailyVitaminCInt)
dailyVitaminD = str(dailyVitaminDInt)
dailyVitaminE = str(dailyVitaminEInt)
dailyVitaminK = str(dailyVitaminKInt)
dailyThiamin = str(dailyThiaminInt)
dailyRiboflavin = str(dailyRiboflavinInt)
dailyNiacin = str(dailyNiacinInt)
dailyCholine = str(dailyCholineInt)
dailyFolate = str (dailyFolateInt)
if ageGroup == "teenager":
  dailyVegetables = str(dailyVegetablesInt)
  dailyFruits = str(dailyFruitsInt)
  dailyDairy = str(dailyDairyInt)

dailyCalciumGramsInt = dailyCalciumInt/1000
dailyIronGramsInt = dailyIronInt/1000
dailyMagneseumGramsInt = dailyMagneseumInt/1000
dailyPhosphorusGramsInt = dailyPhosphorusInt/1000
dailyPotassiumGramsInt = dailyPotassiumInt/1000
dailySodiumGramsInt = dailysSodiumInt/1000
dailyZincGramsInt = dailyZincInt/1000
dailyCopperGramsInt = dailyCopperInt/1000
dailyManganeseGramsInt = dailyManganeseInt/1000
dailySeleniumGramsInt = dailySeleniumInt/1000
dailyVitaminAGramsInt = dailyVitaminAInt/1000
dailyVitaminB6GramsInt = dailyVitaminB6Int/1000
dailyVitaminB12GramsInt = dailyVitaminB12Int/1000
dailyVitaminCGramsInt = dailyVitaminCInt/1000
dailyVitaminDGramsInt = dailyVitaminDInt/1000
dailyVitaminEGramsInt = dailyVitaminEInt/1000
dailyVitaminKGramsInt = dailyVitaminKInt/1000
dailyThiaminGramsInt = dailyThiaminInt/1000
dailyRiboflavinGramsInt = dailyRiboflavinInt/1000
dailyNiacinGramsInt = dailyNiacinInt/1000
dailyCholineGramsInt = dailyCholineInt/1000
dailyFolateGramsInt = dailyFolateInt/1000
if ageGroup == "teenager":
  dailyVegetablesOuncesInt = dailyVegetablesInt*8
  dailyFruitsOuncesInt = dailyFruitsInt*8
  dailyDairyOuncesInt = dailyDairyInt*8

dailyCalciumGrams = str(dailyCalciumGramsInt)
dailyIronGrams = str(dailyIronGramsInt)
dailyMagneseumGrams = str(dailyMagneseumGramsInt)
dailyPhosphorusGrams = str(dailyPhosphorusGramsInt)
dailyPotassiumGrams = str(dailyPotassiumGramsInt)
dailySodiumGrams = str (dailySodiumGramsInt)
dailyZincGrams = str(dailyZincGramsInt)
dailyCopperGrams = str(dailyCopperGramsInt)
dailyManganeseGrams = str(dailyManganeseGramsInt)
dailySeleniumGrams = str(dailySeleniumGramsInt)
dailyVitaminAGrams = str(dailyVitaminAGramsInt)
dailyVitaminB6Grams = str(dailyVitaminB6GramsInt)
dailyVitaminB12Grams = str(dailyVitaminB12GramsInt)
dailyVitaminCGrams = str(dailyVitaminCGramsInt)
dailyVitaminDGrams = str(dailyVitaminDGramsInt)
dailyVitaminEGrams = str(dailyVitaminEGramsInt)
dailyVitaminKGrams = str(dailyVitaminKGramsInt)
dailyThiaminGrams = str(dailyThiaminGramsInt)
dailyRiboflavinGrams = str(dailyRiboflavinGramsInt)
dailyNiacinGrams = str(dailyNiacinGramsInt)
dailyCholineGrams = str(dailyCholineGramsInt)
dailyFolateGrams = str(dailyFolateGramsInt)
if ageGroup == "teenager":
  dailyVegtablesOunces = str(dailyVegetablesOuncesInt)
  dailyFruitsOunces = str(dailyFruitsOuncesInt)
  dailyDairyOunces = str(dailyDairyOuncesInt)

print("You should be getting about "   dailyCalories   " calories per day.")
print("You should be getting about "   dailyProtein   " grams of protein per day.")
print("You should be getting about "   dailyCarbohydrate   " grams of carbohydrates per day.")
print("You should be getting about "   dailyDietaryFiber   " grams of dietary fiber per day.")
print("Between "   dailyTotalFatLower   "% and "   dailyTotalFatUpper   "% of your daily calories should come from total fat.")
print("No more than "   dailySaturatedFat   "% of your daily total fat should come from saturated fat.")
print(dailyLinoleicAcid   " grams per day is an adequate amount of linoleic acid.")
print(dailyLinolenicAcid   " grams per day is an adequate amount of linolenic acid.")
print("You should be getting about "   dailyCalcium   " milligrams ("   dailyCalciumGrams   " grams) of calcium per day.")
print("You should be getting about "   dailyIron   " milligrams ("   dailyIronGrams   " grams) of iron per day.")
print("You should be getting about "   dailyMagneseium   " milligrams ("   dailyMagneseumGrams   " grams) of magneseum per day.")
print("You should be getting about "   dailyPhosphorus   " milligrams ("   dailyPhosphorusGrams   " grams) of phosphorus per day.")
print(dailyPotassium   " milligrams ("   dailyPotassiumGrams   " grams per day is an adequate amount of potassium.")
print("You should be getting no more than "   dailySodium   " milligrams ("   dailySodiumGrams   " grams) of sodium per day.")
print("You should be getting about "   dailyZinc   " milligrams ("   dailyZincGrams   " grams) of zinc per day.")
print("You should be getting about "   dailyCopper   " milligrams ("   dailyCopperGrams   " grams) of copper per day.")
print(dailyManganese   " milligrams ("   dailyManganeseGrams   " grams) per day is an adequate amount of manganese.")
print("You should be getting about "   dailyVitaminA   " milligrams ("   dailyVitaminAGrams   " grams) of Vitamin A per day.")
print("You should be getting about "   dailyVitaminB6   " milligrams ("   dailyVitaminB6Grams   " grams) of Vitamin B-6 per day.")
print("You should be getting about "   dailyVitaminB12   " milligrams ("   dailyVitaminB12Grams   " grams) of Vitamin B-12 per day.")
print("You should be getting about "   dailyVitaminC   " milligrams ("   dailyVitaminCGrams   " grams) of Vitamin C per day.")
print("You should be getting about "   dailyVitaminD   " milligrams ("   dailyVitaminDGrams   " grams) of Vitamin D per day.")
print("You should be getting about "   dailyVitaminE   " milligrams ("   dailyVitaminEGrams   " grams) of Vitamin E per day.")
print(dailyVitaminK   " milligrams ("   dailyVitaminKGrams   " grams) per day is an adequate amount of Vitamin K.")
print("You should be getting about "   dailyThiamin   " milligrams ("   dailyThiaminGrams   " grams) of thiamin per day.")
print("You should be getting about "   dailyRiboflavin   " milligrams ("   dailyRiboflavinGrams   " grams) of riboflavin per day.")
print("You should be getting about "   dailyNiacin   " milligrams ("   dailyNiacinGrams   " grams) of niacin per day.")
print(dailyCholine   " milligrams ("   dailyCholineGrams   " grams) per day is an adequate amount of choline.")
print("You should be getting about "   dailyFolate   " milligrams ("   dailyFolateGrams   " grams) of folate per day.")
if ageGroup == "teenager":
  print("You should be eating about "   dailyVegetables   " cups ("   dailyVegetablesOunces   " ounces) of vegetables per day.")
  print("You should be eating about "   dailyFruits   " cups ("   dailyFruitsOunces   " ounces) of fruits each day.")
  print("You should be eating about "   dailyDairy   " cups ("   dailyDairyOunces   " ounces) of dairy each day.")

I don't know what is wrong with Replit, but it isn't showing the entire error, only part of it. This is the part of the error that I can see:

Traceback (most recent call last):
                       4      <module>
     f  g    u
N              ' g     u '          f

Not sure if the partial error helps.

CodePudding user response:

Here is a working solution. But the code could be improved, see at the bottom there are some recommendations.

error001 = "\nError 001: Invalid Sex!"
error002 = "\nError 002: Invalid Age!"
error003 = "\nError 003: Invalid Activity Level!"
error004 = "\nError 004: Invalid Age Group!"

print("Hello! Welcome to Nutrition Info!")

sexInput = input(
    "To get started, choose the sex of your character (gender, sexual orientation, etc. do not matter, as these do not matter for your physical health). Type 'M' for male or 'F' for female.")

if sexInput == "M":
    sex = "male"
    print("You have selected a male character.")
elif sexInput == "F":
    sex = "female"
    print("You have selected a female character.")
else:
    quit(error001)

ageInput = input("How old is your character? Type just the number.")

if ageInput.isnumeric():
    age = int(ageInput)  # It should be casted after checking is numeric

    if age in range(1, 3):
        ageGroup = "toddler"
    elif age in range(4, 8):
        ageGroup = "young child"
    elif age in range(9, 13):
        ageGroup = "older child"
    elif age in range(14, 18):
        ageGroup = "teenager"
    elif age in range(19, 30):
        ageGroup = "young adult"
    elif age in range(31, 50):
        ageGroup = "older adult"
    elif age in range(51, 130):
        ageGroup = "senior"
    else:
        quit(error002)
else:
    quit(error002)

print("You have selected a "   ageInput   f"-year-old character, which is {ageGroup}.")

if ageGroup == "toddler":
    dailyCaloriesInt = 1000
    dailyProteinInt = 13
    dailyCarbohydrateInt = 130
    dailyDietryFiberInt = 14
    dailyTotalFatLowerInt = 30
    dailyTotalFatUpperInt = 40
    dailySaturatedFat = 10
    dailyLinoleicAcidInt = 7
    dailyLinolenicAcidInt = 0.7
    dailyCalciumInt = 700
    dailyIronInt = 7
    dailyMagnesiumInt = 80
    dailyPhosphorusInt = 260
    dailyPotassiumInt = 3000
    dailySodiumInt = 1500
    dailyZincInt = 3
    dailyCopperInt = 0.34
    dailyManganeseInt = 1.2
    dailySeleniumInt = 20
    dailyVitaminAInt = 300
    dailyVitaminB6Int = 0.5
    dailyVitaminB12Int = 0.9
    dailyVitaminCInt = 15
    dailyVitaminDInt = 600
    dailyVitaminEInt = 6
    dailyVitaminKInt = 30
    dailyThiaminInt = 0.5
    dailyRiboflavinInt = 0.5
    dailyNiacinInt = 6
    dailyCholineInt = 200
    dailyFolateInt = 150
elif ageGroup == "young child":
    dailyProteinInt = 19
    dailyCarbohydrateInt = 130
    dailyTotalFatLowerInt = 25
    dailyTotalFatUpperInt = 35
    dailySaturatedFat = 10
    dailyLinoleicAcidInt = 10
    dailyLinolenicAcidInt = 0.9
    dailyCalciumInt = 1000
    dailyIronInt = 10
    dailyMagnesiumInt = 130
    dailyPhosphorusInt = 500
    dailyPotassiumInt = 3800
    dailySodiumInt = 1900
    dailyZincInt = 5
    dailyCopperInt = 0.44
    dailyManganeseInt = 1.5
    dailySeleniumInt = 30
    dailyVitaminAInt = 400
    dailyVitaminB6Int = 0.6
    dailyVitaminB12Int = 1.2
    dailyVitaminCInt = 25
    dailyVitaminDInt = 600
    dailyVitaminEInt = 7
    dailyVitaminKInt = 55
    dailyThiaminInt = 0.6
    dailyRiboflavinInt = 0.6
    dailyNiacinInt = 8
    dailyCholineInt = 0.6
    dailyFolateInt = 1.2

    if sex == "female":
        dailyCaloriesInt = 1200
        dailyDietaryFiberInt = 16.8
    else:  # If it's not female, for sure will be "male", it was checked before
        dailyDietaryFiberInt = 19.6

        activityInputMaleYoungChild = input(
            "How active is your character? Type '1' for inactive or '2' for active.")

        if activityInputMaleYoungChild == "1":
            activity = "inactive"
            dailyCaloriesInt = 1400  # Not needed to add another if statement
        elif activityInputMaleYoungChild == "2":
            activity = "active"
            dailyCaloriesInt = 1600  # Not needed to add another elif statement
        else:
            quit(error003)

elif ageGroup == "older child":
    dailyProteinInt = 34
    dailyCarbohydrateInt = 130
    dailyTotalFatLowerInt = 25
    dailyTotalFatUpperInt = 35
    dailySaturatedFat = 10
    dailyCalciumInt = 1300
    dailyIronInt = 8
    dailyMagnesiumInt = 240
    dailyPhosphorusInt = 1250
    dailyPotassiumInt = 4500
    dailySodiumInt = 2200
    dailyZincInt = 8
    dailyCopperInt = 0.7
    dailySeleniumInt = 40
    dailyVitaminAInt = 600
    dailyVitaminB6Int = 1
    dailyVitaminB12Int = 1.8
    dailyVitaminCInt = 45
    dailyVitaminDInt = 600
    dailyVitaminEInt = 11
    dailyVitaminKInt = 60
    dailyThiaminInt = 0.9
    dailyRiboflavinInt = 0.9
    dailyNiacinInt = 12
    dailyCholineInt = 375
    dailyFolateInt = 300

    if sex == "female":
        dailyCaloriesInt = 1600
        dailyDietaryFiberInt = 22.4
        dailyLinoleicAcidInt = 10
        dailyLinolenicAcidInt = 1
        dailyManganeseInt = 1.6
    else:  # If it's not female, for sure will be "male", it was checked before
        dailyCaloriesInt = 1800
        dailyFietaryFiberInt = 25.2
        dailyLinoleicAcidInt = 12
        dailyLinolenicAcidInt = 1.2
        dailyManganeseInt = 1.9

elif ageGroup == "teenager":
    dailyCarbohydrateInt = 130
    dailyTotalFatLowerInt = 25
    dailyTotalFatUpperInt = 35
    dailySaturatedFat = "10"
    dailyCalciumInt = 1300
    dailyPhosphorusInt = 1250
    dailyPotassiumInt = 4700
    dailySodiumInt = 2300
    dailyCopperInt = 0.89
    dailySeleniumInt = 55
    dailyVitaminDInt = 600
    dailyVitaminEInt = 15
    dailyDairyInt = 3

    if sex == "female":
        dailyCaloriesInt = 1800
        dailyProteinInt = 46
        dailyDietaryFiberInt = 25.2
        dailyLinoleicAcidInt = 11
        dailyLinolenicAcidInt = 1.1
        dailyIronInt = 15
        dailyMagnesiumInt = 360
        dailyZincInt = 9
        dailyManganeseInt = 1.6
        dailyVitaminAInt = 700
        dailyVitaminB6Int = 1.2
        dailyVitaminCInt = 65
        dailyThiaminInt = 1
        dailyRiboflavinInt = 1
        dailyNiacinInt = 14
        dailyCholineInt = 400

        activityInputFemaleTeenager = input(
            "How active is your character? Type '1' for inactive, '2' for moderately active, or '3' for active, then press the 'ENTER' or 'RETURN' key.")

        if activityInputFemaleTeenager == "1":
            activity = "inactive"
        elif activityInputFemaleTeenager == "2":
            activity = "moderately active"
        elif activityInputFemaleTeenager == "3":
            activity = "active"
        else:
            quit(error003)

        if activity == "inactive":
            dailyCaloriesInt = 1800
            dailyGrainsInt = 6
            dailyVegetablesInt = 2.5
            dailyFruitsInt = 1.5
        elif activity == "moderately active":
            dailyCaloriesInt = 2000
            dailyGrainsInt = 6
            dailyVegetablesInt = 2.5
            dailyFruitsInt = 2
        elif activity == "active":
            dailyCaloriesInt = 2400
            dailyGrainsInt = 8
            dailyVegetablesInt = 3
            dailyFruitsInt = 2
        else:
            quit(error003)
    else:  # If it's not female, for sure will be "male", it was checked before
        dailyProteinInt = 52
        dailyDietaryFiberInt = 30.8
        dailyLinoleicAcidInt = 16
        dailyLinolenicAcidInt = 1.6
        dailyIronInt = 11
        dailyMagnesiumInt = 410
        dailyZincInt = 11
        dailyManganeseInt = 2.2
        dailyVitaminAInt = 900
        dailyVitaminB6Int = 1.3
        dailyVitaminCInt = 75
        dailyThiaminInt = 1.2
        dailyRiboflavinInt = 1.3
        dailyNiacinInt = 1.6
        dailyCholineInt = 550

        activityInputMaleTeenager = input(
            "How active is your character? Type '1' for inactive, '2' for moderately active, or '3' for active, then press the 'ENTER' or 'RETURN' key.")

        if activityInputMaleTeenager == "1":
            activty = "inactive"
            dailyCaloriesInt = 2200  # Not needed to add another if statement
            dailyGrainsInt = 7
            dailyVegetablesInt = 3
            dailyFruitsInt = 2
        elif activityInputMaleTeenager == "2":
            activity = "moderately active"
            dailyCaloriesInt = 2800  # Not needed to add another elif statement
            dailyGrainsInt = 10
            dailyVegetablesInt = 3.5
            dailyFruitsInt = 2.5
        elif activityInputMaleTeenager == "3":
            activity = "active"
            dailyCaloriesInt = 3200  # Not needed to add another elif statement
            dailyGrainsInt = 10
            dailyVegetablesInt = 4
            dailyFruitsInt = 2.5
        else:
            quit(error003)

elif ageGroup == "young adult":
    dailyCarbohydateInt = 130
    dailyTotalFatLowerInt = 20
    dailyTotalFatUpperInt = 35
    dailySaturatedFat = 10
    dailyCalciumInt = 1000
    dailyPhosphorusInt = 700
    dailyPotassiumInt = 4700
    dailySodiumInt = 2300
    dailyCopperInt = 0.9
    dailySeleniumInt = 55
    dailyVitaminB6Int = 1.3
    dailyVitaminB12Int = 2.4
    dailyVitaminDInt = 600
    dailyVitaminEInt = 15
    dailyFolateInt = 400

    if sex == "female":
        dailyCaloriesInt = 2000
        dailyProteinInt = 46
        dailyDietaryFiberInt = 28
        dailyLinoleicAcidInt = 12
        dailyLinolenicAcidInt = 1.1
        dailyIronInt = 18
        dailyMagneseumInt = 310
        dailyZincInt = 8
        dailyManganeseInt = 1.8
        dailyVitaminAInt = 700
        dailyVitaminCInt = 75
        dailyVitaminKInt = 90
        dailyThimainInt = 1.1
        dailyRiboflavinInt = 1.1
        dailyNiacinInt = 14
        dailyCholineInt = 425
    else:  # If it's not female, for sure will be "male", it was checked before
        dailyProteinInt = 56
        dailyDietaryFiberInt = 33.6
        dailyLinoleicAcidInt = 17
        dailyLinolenicAcidInt = 1.6
        dailyIronInt = 8
        dailyMagneseumInt = 400
        dailyZincInt = 11
        dailyManganeseInt = 2.3
        dailyVitaminAInt = 900
        dailyVitaminCInt = 90
        dailyVitaminKInt = 120
        dailyThiaminInt = 1.2
        dailyRiboflavinInt = 1.3
        dailyNiacinInt = 16
        dailyCholineInt = 550

        activityInputMaleYoungAdult = input(
            "How active is your character? Type '1' for inactive, '2' for moderately active, or '3' for active.")

        if activityInputMaleYoungAdult == "1":
            activity = "inactive"
            dailyCaloriesInt = 2400  # Not needed to add another if statement
        elif activityInputMaleYoungAdult == "2":
            activty = "moderately active"
            dailyCaloriesInt = 2600  # Not needed to add another elif statement
        elif activityInputMaleYoungAdult == "3":
            activity = "active"
            dailyCaloriesInt = 3000  # Not needed to add another elif statement
        else:
            quit(error003)

elif ageGroup == "older adult":
    dailyCarbohydateInt = 130
    dailyTotalFatLowerInt = 20
    dailyTotalFatUpperInt = 35
    dailySaturatedFat = 10
    dailyCalciumInt = 1000
    dailyPhosphorusInt = 700
    dailyPotassiumInt = 4700
    dailySodiumInt = 2300
    dailyCopperInt = 0.9
    dailySeleniumInt = 55
    dailyVitaminB6Int = 1.3
    dailyVitaminB12Int = 2.4
    dailyVitaminDInt = 600
    dailyVitaminEInt = 15
    dailyFolateInt = 400

    if sex == "female":
        dailyCaloriesInt = 1800
        dailyProteinInt = 46
        dailyDietaryFiberInt = 25.2
        dailyLinoleicAcidInt = 12
        dailyLinolenicAcidInt = 1.1
        dailyIronInt = 18
        dailyMagneseumInt = 320
        dailyZincInt = 8
        dailyManganeseInt = 1.8
        dailyVitaminAInt = 700
        dailyVitaminCInt = 75
        dailyVitaminKInt = 90
        dailyThimainInt = 1.1
        dailyRiboflavinInt = 1.1
        dailyNiacinInt = 14
        dailyCholineInt = 425
    else:  # If it's not female, for sure will be "male", it was checked before
        dailyCaloriesInt = 2200
        dailyProteinInt = 56
        dailyDietaryFiberInt = 30.8
        dailyLinoleicAcidInt = 17
        dailyLinolenicAcidInt = 1.6
        dailyIronInt = 8
        dailyMagneseumInt = 420
        dailyZincInt = 11
        dailyManganeseInt = 2.3
        dailyVitaminAInt = 900
        dailyVitaminCInt = 90
        dailyVitaminKInt = 120
        dailyThiaminInt = 1.2
        dailyRiboflavinInt = 1.3
        dailyNiacinInt = 16
        dailyCholineInt = 550

elif ageGroup == "senior":
    dailyCarbohydateInt = 130
    dailyTotalFatLowerInt = 20
    dailyTotalFatUpperInt = 35
    dailySaturatedFat = 10
    dailyCalciumInt = 1000
    dailyIronInt = 8
    dailyPhosphorusInt = 700
    dailyPotassiumInt = 4700
    dailySodiumInt = 2300
    dailyCopperInt = 0.9
    dailySeleniumInt = 55
    dailyVitaminB12Int = 2.4
    dailyVitaminDInt = 600
    dailyVitaminEInt = 15
    dailyFolateInt = 400

    if sex == "female":
        dailyCaloriesInt = 2000
        dailyProteinInt = 46
        dailyDietaryFiberInt = 22.4
        dailyLinoleicAcidInt = 11
        dailyLinolenicAcidInt = 1.1
        dailyMagneseumInt = 310
        dailyZincInt = 8
        dailyManganeseInt = 1.8
        dailyVitaminAInt = 700
        dailyVitaminB6Int = 1.5
        dailyVitaminCInt = 75
        dailyVitaminKInt = 90
        dailyThimainInt = 1.1
        dailyRiboflavinInt = 1.1
        dailyNiacinInt = 14
        dailyCholineInt = 425
    else:  # If it's not female, for sure will be "male", it was checked before
        dailyProteinInt = 56
        dailyDietaryFiberInt = 28
        dailyLinoleicAcidInt = 14
        dailyLinolenicAcidInt = 1.6
        dailyMagneseumInt = 400
        dailyZincInt = 11
        dailyManganeseInt = 2.3
        dailyVitaminAInt = 900
        dailyVitaminB6Int = 1.7
        dailyVitaminCInt = 90
        dailyVitaminKInt = 120
        dailyThiaminInt = 1.2
        dailyRiboflavinInt = 1.3
        dailyNiacinInt = 16
        dailyCholineInt = 550

else:
    quit(error004)

try:
    if activity == "inactive":
        print("You have selected an inactive character.")
    if activity == "moderately active":
        print("You have selected a moderately active character.")
    if activity == "active":
        print("You have selected an active character.")
except NameError:
    print("You have NOT selected any activity.")  # Skipping "referenced before assignment" Traceback

dailyCalories = str(dailyCaloriesInt) if 'dailyCalories' in locals() else '?'
dailyProtein = str(dailyProteinInt) if 'dailyProteinInt' in locals() else '?'
dailyCarbohydrate = str(dailyCarbohydrateInt) if 'dailyCarbohydrateInt' in locals() else '?'
dailyDietaryFiber = str(dailyDietaryFiberInt) if 'dailyDietaryFiberInt' in locals() else '?'
dailyTotalFatLower = str(dailyTotalFatLowerInt) if 'dailyTotalFatLowerInt' in locals() else '?'
dailyTotalFatUpper = str(dailyTotalFatUpperInt) if 'dailyTotalFatUpperInt' in locals() else '?'
dailySaturatedFat = str(dailySaturatedFatInt) if 'dailySaturatedFatInt' in locals() else '?'
dailyLinoleicAcid = str(dailyLinoleicAcidInt) if 'dailyLinoleicAcidInt' in locals() else '?'
dailyLinolenicAcid = str(dailyLinolenicAcidInt) if 'dailyLinolenicAcidInt' in locals() else '?'
dailyCalcium = str(dailyCalciumInt) if 'dailyCalciumInt' in locals() else '?'
dailyIron = str(dailyIronInt) if 'dailyIronInt' in locals() else '?'
dailyMagneseum = str(dailyMagneseumInt) if 'dailyMagneseumInt' in locals() else '?'
dailyPhosphorus = str(dailyPhosphorusInt) if 'dailyPhosphorusInt' in locals() else '?'
dailyPotassium = str(dailyPotassiumInt) if 'dailyPotassiumInt' in locals() else '?'
dailySodium = str(dailySodiumInt) if 'dailySodiumInt' in locals() else '?'
dailyZinc = str(dailyZincInt) if 'dailyZincInt' in locals() else '?'
dailyCopper = str(dailyCopperInt) if 'dailyCopperInt' in locals() else '?'
dailyManganese = str(dailyManganeseInt) if 'dailyManganeseInt' in locals() else '?'
dailySelenium = str(dailySeleniumInt) if 'dailySeleniumInt' in locals() else '?'
dailyVitaminA = str(dailyVitaminAInt) if 'dailyVitaminAInt' in locals() else '?'
dailyVitaminB6 = str(dailyVitaminB6Int) if 'dailyVitaminB6Int' in locals() else '?'
dailyVitaminB12 = str(dailyVitaminB12Int) if 'dailyVitaminB12Int' in locals() else '?'
dailyVitaminC = str(dailyVitaminCInt) if 'dailyVitaminCInt' in locals() else '?'
dailyVitaminD = str(dailyVitaminDInt) if 'dailyVitaminDInt' in locals() else '?'
dailyVitaminE = str(dailyVitaminEInt) if 'dailyVitaminEInt' in locals() else '?'
dailyVitaminK = str(dailyVitaminKInt) if 'dailyVitaminKInt' in locals() else '?'
dailyThiamin = str(dailyThiaminInt) if 'dailyThiaminInt' in locals() else '?'
dailyRiboflavin = str(dailyRiboflavinInt) if 'dailyRiboflavinInt' in locals() else '?'
dailyNiacin = str(dailyNiacinInt) if 'dailyNiacinInt' in locals() else '?'
dailyCholine = str(dailyCholineInt) if 'dailyCholineInt' in locals() else '?'
dailyFolate = str(dailyFolateInt) if 'dailyFolateInt' in locals() else '?'
if ageGroup == "teenager":
    dailyVegetables = str(dailyVegetablesInt) if 'dailyVegetablesInt' in locals() else '?'
    dailyFruits = str(dailyFruitsInt) if 'dailyFruitsInt' in locals() else '?'
    dailyDairy = str(dailyDairyInt) if 'dailyDairyInt' in locals() else '?'

dailyCalciumGrams = str(dailyCalciumInt / 1000) if 'dailyCalciumInt' in locals() else '?'
dailyIronGrams = str(dailyIronInt / 1000) if 'dailyIronInt' in locals() else '?'
dailyMagneseumGrams = str(dailyMagneseumInt / 1000) if 'dailyMagneseumInt' in locals() else '?'
dailyPhosphorusGrams = str(dailyPhosphorusInt / 1000) if 'dailyPhosphorusInt' in locals() else '?'
dailyPotassiumGrams = str(dailyPotassiumInt / 1000) if 'dailyPotassiumInt' in locals() else '?'
dailySodiumGrams = str(dailysSodiumInt / 1000) if 'dailysSodiumInt' in locals() else '?'
dailyZincGrams = str(dailyZincInt / 1000) if 'dailyZincInt' in locals() else '?'
dailyCopperGrams = str(dailyCopperInt / 1000) if 'dailyCopperInt' in locals() else '?'
dailyManganeseGrams = str(dailyManganeseInt / 1000) if 'dailyManganeseInt' in locals() else '?'
dailySeleniumGrams = str(dailySeleniumInt / 1000) if 'dailySeleniumInt' in locals() else '?'
dailyVitaminAGrams = str(dailyVitaminAInt / 1000) if 'dailyVitaminAInt' in locals() else '?'
dailyVitaminB6Grams = str(dailyVitaminB6Int / 1000) if 'dailyVitaminB6Int' in locals() else '?'
dailyVitaminB12Grams = str(dailyVitaminB12Int / 1000) if 'dailyVitaminB12Int' in locals() else '?'
dailyVitaminCGrams = str(dailyVitaminCInt / 1000) if 'dailyVitaminCInt' in locals() else '?'
dailyVitaminDGrams = str(dailyVitaminDInt / 1000) if 'dailyVitaminDInt' in locals() else '?'
dailyVitaminEGrams = str(dailyVitaminEInt / 1000) if 'dailyVitaminEInt' in locals() else '?'
dailyVitaminKGrams = str(dailyVitaminKInt / 1000) if 'dailyVitaminKInt' in locals() else '?'
dailyThiaminGrams = str(dailyThiaminInt / 1000) if 'dailyThiaminInt' in locals() else '?'
dailyRiboflavinGrams = str(dailyRiboflavinInt / 1000) if 'dailyRiboflavinInt' in locals() else '?'
dailyNiacinGrams = str(dailyNiacinInt / 1000) if 'dailyNiacinInt' in locals() else '?'
dailyCholineGrams = str(dailyCholineInt / 1000) if 'dailyCholineInt' in locals() else '?'
dailyFolateGrams = str(dailyFolateInt / 1000) if 'dailyFolateInt' in locals() else '?'
if ageGroup == "teenager":
    dailyVegetablesOunces = str(dailyVegetablesInt * 8) if 'dailyVegetablesInt' in locals() else '?'
    dailyFruitsOunces = str(dailyFruitsInt * 8) if 'dailyFruitsInt' in locals() else '?'
    dailyDairyOunces = str(dailyDairyInt * 8) if 'dailyDairyInt' in locals() else '?'

print("You should be getting about "   dailyCalories   " calories per day.")
print("You should be getting about "   dailyProtein   " grams of protein per day.")
print("You should be getting about "   dailyCarbohydrate   " grams of carbohydrates per day.")
print("You should be getting about "   dailyDietaryFiber   " grams of dietary fiber per day.")
print(
    "Between "   dailyTotalFatLower   "% and "   dailyTotalFatUpper   "% of your daily calories should come from total fat.")
print("No more than "   dailySaturatedFat   "% of your daily total fat should come from saturated fat.")
print(dailyLinoleicAcid   " grams per day is an adequate amount of linoleic acid.")
print(dailyLinolenicAcid   " grams per day is an adequate amount of linolenic acid.")
print(
    "You should be getting about "   dailyCalcium   " milligrams ("   dailyCalciumGrams   " grams) of calcium per day.")
print("You should be getting about "   dailyIron   " milligrams ("   dailyIronGrams   " grams) of iron per day.")
# This is not defined!
# print(
#     "You should be getting about "   dailyMagneseium   " milligrams ("   dailyMagneseumGrams   " grams) of magneseum per day.")
print(
    "You should be getting about "   dailyPhosphorus   " milligrams ("   dailyPhosphorusGrams   " grams) of phosphorus per day.")
print(dailyPotassium   " milligrams ("   dailyPotassiumGrams   " grams per day is an adequate amount of potassium.")
print(
    "You should be getting no more than "   dailySodium   " milligrams ("   dailySodiumGrams   " grams) of sodium per day.")
print("You should be getting about "   dailyZinc   " milligrams ("   dailyZincGrams   " grams) of zinc per day.")
print(
    "You should be getting about "   dailyCopper   " milligrams ("   dailyCopperGrams   " grams) of copper per day.")
print(
    dailyManganese   " milligrams ("   dailyManganeseGrams   " grams) per day is an adequate amount of manganese.")
print(
    "You should be getting about "   dailyVitaminA   " milligrams ("   dailyVitaminAGrams   " grams) of Vitamin A per day.")
print(
    "You should be getting about "   dailyVitaminB6   " milligrams ("   dailyVitaminB6Grams   " grams) of Vitamin B-6 per day.")
print(
    "You should be getting about "   dailyVitaminB12   " milligrams ("   dailyVitaminB12Grams   " grams) of Vitamin B-12 per day.")
print(
    "You should be getting about "   dailyVitaminC   " milligrams ("   dailyVitaminCGrams   " grams) of Vitamin C per day.")
print(
    "You should be getting about "   dailyVitaminD   " milligrams ("   dailyVitaminDGrams   " grams) of Vitamin D per day.")
print(
    "You should be getting about "   dailyVitaminE   " milligrams ("   dailyVitaminEGrams   " grams) of Vitamin E per day.")
print(dailyVitaminK   " milligrams ("   dailyVitaminKGrams   " grams) per day is an adequate amount of Vitamin K.")
print(
    "You should be getting about "   dailyThiamin   " milligrams ("   dailyThiaminGrams   " grams) of thiamin per day.")
print(
    "You should be getting about "   dailyRiboflavin   " milligrams ("   dailyRiboflavinGrams   " grams) of riboflavin per day.")
print(
    "You should be getting about "   dailyNiacin   " milligrams ("   dailyNiacinGrams   " grams) of niacin per day.")
print(dailyCholine   " milligrams ("   dailyCholineGrams   " grams) per day is an adequate amount of choline.")
print(
    "You should be getting about "   dailyFolate   " milligrams ("   dailyFolateGrams   " grams) of folate per day.")
if ageGroup == "teenager":
    print(
        "You should be eating about "   dailyVegetables   " cups ("   dailyVegetablesOunces   " ounces) of vegetables per day.")
    print(
        "You should be eating about "   dailyFruits   " cups ("   dailyFruitsOunces   " ounces) of fruits each day.")
    print("You should be eating about "   dailyDairy   " cups ("   dailyDairyOunces   " ounces) of dairy each day.")

Recommendations:

  • Use functions, this is too long.

  • In your future new implementation avoid using "locals()", it's a dirty shortcut just to make it work in the way you had the code

  • Use classes with attributes or something to keep the different multiple options you have. A simple example:

     class Errors(str):
         Sex = "Error 001: Invalid Sex!"
         Age = "Error 002: Invalid Age!"
         Activity = "Error 003: Invalid Activity Level!"
         Group = "Error 004: Invalid Age Group!"
    
     # Use it like this:
     quit(Errors.Sex)
    
  • Avoid statements doing the same

  • Don't check something more than once

  • Catch exceptions with try-except

  • Take care with variables referenced before assign them. I used locals() as shortcut, avoid that. Another option could be to initialize all the variables.

  • Clean the code and save data somehow out of the main function

  • Related