Python Forum
Starting to use functions help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Starting to use functions help
#3
You dont have the local variable t defined when you try to use it in the function ballTime, so line ballHeight = (h + (v*t) - (16*t*t)) will raise an error. Even if you defined t in ballTime (or passed it like an argument), you are not recalculating height in your while loop, so it be will infinite loop.

And as wavic pointed out, your code is not easy to follow. There is no reason why you should chain all your functions together, especially if that means that function named getInput is responsible for getting input, checking it, computing and printing results. Probably you should replace it with simpler, more "procedural" approach and use return values of functions.

Something like (just pseudocode hints):
...
your modified functions
...
def main():
     h, v = getInput()        # getInput only gets (and checks) input values and returns them
     maxH = maxHeight(h, v)   # maxHeight returns computed height
     print(..... maxH)
     ballT = ballTime(h, v)   # ballTime returns ball time
     print(..... ballT)

if __name__ == "__main__":
    main()
Reply


Messages In This Thread
Starting to use functions help - by Miraclefruit - Mar-22-2017, 02:39 AM
RE: Starting to use functions help - by wavic - Mar-22-2017, 07:08 AM
RE: Starting to use functions help - by zivoni - Mar-22-2017, 08:52 AM
RE: Starting to use functions help - by wavic - Mar-22-2017, 09:01 AM
RE: Starting to use functions help - by nilamo - Mar-22-2017, 04:05 PM

Forum Jump:

User Panel Messages

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