using 2 functions in addition to main program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hamady2001
    New Member
    • Feb 2008
    • 2

    using 2 functions in addition to main program

    Hello everyone this is my first post and I just started my Python class. I am stuck on an assignment...pl ease help

    I have to redo the below program (from a prior assignment) to include 2 functions in addition to main program. The first function should ask for the hours and return them to the main program. The second function should receive the hours from the main program, calculate the minutes and display them


    original program code referring to question above

    def main():
    print"This program converts hours to minutes"
    hours = input ("Please enter the number of hours to be converted: ")
    minutes = hours * 60
    print "The number of minutes is:", minutes
    main()


    what I have so far

    def intromsg():
    print "This program converts hours to minutes"
    def gethours():
    hour = input ("Enter the number of hours: ")
    return score
    def minutes():
    total = gethours() * 60

    def main():
    intromsg()
    gethours()
    minutes()

    Its probably something so simple. I think I am incorrectly getting the hours from the user to be multiplied by 60 to show minutes. Please Help
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by hamady2001
    Hello everyone this is my first post and I just started my Python class. I am stuck on an assignment...pl ease help

    I have to redo the below program (from a prior assignment) to include 2 functions in addition to main program. The first function should ask for the hours and return them to the main program. The second function should receive the hours from the main program, calculate the minutes and display them


    original program code referring to question above

    def main():
    print"This program converts hours to minutes"
    hours = input ("Please enter the number of hours to be converted: ")
    minutes = hours * 60
    print "The number of minutes is:", minutes
    main()


    what I have so far

    def intromsg():
    print "This program converts hours to minutes"
    def gethours():
    hour = input ("Enter the number of hours: ")
    return score
    def minutes():
    total = gethours() * 60

    def main():
    intromsg()
    gethours()
    minutes()

    Its probably something so simple. I think I am incorrectly getting the hours from the user to be multiplied by 60 to show minutes. Please Help
    Thanks for trying to show your code structure with indention tags, but you should use code tags instead.

    gethours() should return hours instead of score. score is not defined. You should assign the value returned by a function to a variable name. Pass a variable name to a function, and assign the returned value to another variable. Example (with code tags): [code=Python]
    # This function returns a value
    def getdeg():
    return float(raw_input ("Enter temp in degrees F"))
    # This function receives an argument and returns a value
    def FtoC(deg):
    return (deg-32)*(5.0/9.0)

    degF = getdeg()
    degC = FtoC(degF)
    print degC[/code]HTH

    Comment

    • hamady2001
      New Member
      • Feb 2008
      • 2

      #3
      Thanks for your time and effort in helping me. I have completed my assignment. Thanks!

      Comment

      Working...