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
#6
The calculation function doesn't return anything.
You can add the planet as a parameter and create a dict.

lbs = ask_weight()
def calculation(lbs, planet):
    mass = lbs/9.807
    weight = {
        'mercury': mass*3.7,
        'venus':mass*8.87,
        'mars': mass*3.71,
        'jupiter': mass*24.92,
        'saturn': mass*10.44,
        'uranus': mass*8.87,
        'neptune': mass*11.15,
        'pluto': mass*0.58} # pluto. Actually Pluto is no more a part of the nine. http://www.bbc.com/news/science-environment-33462184

     return weight[planet]

def ask_weight():
    lbs = float(input("How many pounds do you weigh? "))
    return lbs # the function have to return a value. lbs is a local to the fuction variable.

def ask_planet():
    planet = input("Which planet would you like to know your weight for? ")
    return planet # same here
And then:
 
    planet = ask_planet().lower()
    lbs = ask_weight()

    # if is not needed because we have a dict and we using the planet name to determine the desired value
    print("Your weight on {} would be {} pounds.".format(planet.title(), calculation(lbs, planet))
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
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 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