Python Forum
Help with parameter variables losing value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with parameter variables losing value
#1
Hello All,

I need help. Can someone tell me why I am not getting any results. Look like I am losing the variables values.
Here is my code.

# Global constant for Calories


CALORIES_FROM_FAT = 9
CALORIES_FROM_CARBS = 4

# main module

# Get grams fat

def main():
gramsFat = gramsCarbs = caloriesFat = caloriesCarbs = 0.0

getFat(gramsFat)
setFat(gramsFat,CALORIES_FROM_FAT)
getCarbs(gramsCarbs)
setCarbs(gramsCarbs, CALORIES_FROM_CARBS)
showCarbs(gramsFat, gramsCarbs, caloriesFat, caloriesCarbs)



# The getFat module gets weight and stores it
# in the inputFat reference variable.

def getFat(gramsFat):
gramsFat = float(input('Enter the number of fat grams consumed: '))


def setFat(gramsFat,CALORIES_FROM_FAT):
caloriesFat = float(gramsFat * CALORIES_FROM_FAT)


def getCarbs(gramsCarbs):
gramsCarbs = float(input("Enter carbohydrate grams consumed: "))




def setCarbs(gramsCarbs, CALORIES_FROM_CARBS):
caloriesCarbs = gramsCarbs * CALORIES_FROM_CARBS

# ------------------------------------------------------------------------
# The showCarbs function accepts the number of grams of fat and of carbs,
# as well as the calories from fat and from carbs, as arguments
# and displays the resulting calories

def showCarbs(gramsFat, gramsCarbs, caloriesFat, caloriesCarbs):
print("Grams of Fat: ", gramsFat)
print("Result calories: ", caloriesFat)
print("Grams of Carbs: ", gramsCarbs)
print("Result calories: ", caloriesCarbs)


# Call Main Function

main()
Reply


Messages In This Thread
Help with parameter variables losing value - by kofipython - Feb-24-2018, 03:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 17,940 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  Environment seems to keep losing references spacedog 2 2,683 Apr-23-2021, 07:36 PM
Last Post: spacedog
  losing memory antioch 1 2,349 Jan-20-2021, 05:29 AM
Last Post: antioch
  Winning/Losing Message Error in Text based Game kdr87 2 3,994 Dec-14-2020, 12:25 AM
Last Post: bowlofred
  SQL Alchemy dynamic class - declarative_base losing attributes mrdominikku 4 5,187 Jan-10-2020, 06:46 PM
Last Post: mrdominikku

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020