Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problem with operation in a simple code to convert your weight in weight of another planet

I decided to write the same program I did in C++ in Python. The only problem is it doesn’t work. I tried tweaking here and there but my result is always the same: "your weight is none kg"

g = 9.81

def operation(x,y):
    (x/g)*y

kg = float(input("Please enter your weight in Kg on earth: "))
print("1)mercury")
print("2)venus")
print("3)mars")
print("4)jupiter")
print("5)saturn")
print("6)uranus")
print("7)neptune")
print("8)pluto")

while True:
    planet = input("Please in what planet do you want to see your weight? ")
    if planet in("1","2","3","4","5","6","7","8"):
        if planet == "1":
            print("your weight in mercury is: ",operation(kg,3.61), "kg")
        elif planet == "2":
            print("your weight in venus is: ",operation(kg,8.87),"kg")
        elif planet == "3":
            print("your weight in mars is: ",operation(kg,3.721),"kg")
        elif planet == "4":
            print("your weight in jupiter",operation(kg,26),"kg")
        elif planet == "5":
            print("your weight in saturn is: ",operation(kg,11.2),"kg")
        elif planet == "6":
            print("your weight in uranus is: ", operation(kg,10.5),"kg")
        elif planet == "7":
            print("your weight in neptune is: ",operation(kg,13.3),"kg")
        elif planet == "8":
            print("your weight on pluto is: ",operation(kg,0.61),"kg")
        continue_1 = input("Do you wish to know your weight on another planet? (yes/no)")
        if continue_1 == "no":
            break
    else:
        print("Thank you for using our program")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I see you are missing return in the operation function.

def operation(x,y):
    return (x/g)*y
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading