Python Forum
Cannot figure out what is wrong
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot figure out what is wrong
#7
You should avoid globals whenever possible. In your case, they are not needed. You are just not using functions correctly. For instance, in order for 'planet_call' to work, you need two pieces of information: the planet and the calculation for that planet (which we will call 'pounds' for now). Now we know our function is
def planet_call(planet, pounds):
You get the value of 'planet' by calling function 'ask_planet()', you get the value from the input(), so you just need to 'return' that value.
def ask_planet():
    planet = input("Which planet would you like to know your weight for? ")
    return planet
The same holds true for the function 'calculation()', in which you need to know the value of 'planet', so:
def calculation(planet):
    # Do calculation. Note you need your 'if/elif/else' here
    return pound
To use them, you need to call them:
user_planet = get_planet()
user_pounds = calculation(user_planet)
user_final = planet_call(user_planet, user_pounds)
Your 'planet_call()' only needs one print statement, the pythonic way would be:
print("Your weight on {} would be {} pounds".format(planet, pounds))
For now, forget about asking for new planets. See if you can get the 'base' working correctly. As was also pointed out, Python is case sensitive so make sure your variables are of the same case.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Messages In This Thread
Cannot figure out what is wrong - by Korbrent - Dec-11-2017, 09:13 PM
RE: Cannot figure out what is wrong - by j.crater - Dec-11-2017, 09:33 PM
RE: Cannot figure out what is wrong - by Korbrent - Dec-11-2017, 09:39 PM
RE: Cannot figure out what is wrong - by squenson - Dec-11-2017, 09:35 PM
RE: Cannot figure out what is wrong - by squenson - Dec-11-2017, 10:14 PM
RE: Cannot figure out what is wrong - by wavic - Dec-11-2017, 11:12 PM
RE: Cannot figure out what is wrong - by sparkz_alot - Dec-11-2017, 11:41 PM
RE: Cannot figure out what is wrong - by Korbrent - Dec-12-2017, 12:00 AM
RE: Cannot figure out what is wrong - by wavic - Dec-12-2017, 12:12 AM
RE: Cannot figure out what is wrong - by Korbrent - Dec-12-2017, 12:17 AM
RE: Cannot figure out what is wrong - by Korbrent - Dec-12-2017, 01:31 AM
RE: Cannot figure out what is wrong - by wavic - Dec-12-2017, 03:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Im so stressed because I cant figure out what I'm doing wrong. BursteXO 2 3,045 Jan-29-2018, 01:16 AM
Last Post: BursteXO

Forum Jump:

User Panel Messages

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