samedi 4 mars 2017

Returning else statement regardless if If conditions met in Python [duplicate]

This question already has an answer here:

##---Initializing Variable----------------------------------------------------------------------#
#-----------------------------------------------------------------------------------------------#
objectMass=0
weight=0

##---Introductory Statement: Welcome to the Program---------------------------------------------#
#-----------------------------------------------------------------------------------------------#
def intro():
    print("\n".join(["---------------------------------------------------------",
              "Hello and Welcome to Mass to Weight Calculator",
              "Today is a good day!",
              "---------------------------------------------------------"]))

##---The getMass module gets user input for mass & stores in getMass reference modules----------#
#-----------------------------------------------------------------------------------------------#
def getMass(): 
    objectMass=float(input("Please enter the Mass of the object you want calculated: "))
    return objectMass

##--The weightConversion module calculates inputted mass into weight----------------------------#
#-----------------------------------------------------------------------------------------------#
def weightConversion(objectMass):
    gravity = 9.8
    weight=float(objectMass)*gravity
    return weight

##--Calculation Module compares weight of object and prints out sentence associated to weight---#
#-----------------------------------------------------------------------------------------------#
def massToWeight(objectMass, weight):
    if weight > 1000:
        print("\n".join(["Holy Smokes, your weight(in newtons) is:", format(weight, ".2f"),
                        "It's way too heavy!!!"]))

    if weight < 10:
        print("Aww man, I can pick this up with one finger.", "It's way too light!",
                        "This weight(in newtons) is:", format(weight, ".2f"))

    else:
        print("This weight(in newtons):", format(weight, ".2f"), "is just right.")
    return

##---Closing Statement--------------------------------------------------------------------------#
#-----------------------------------------------------------------------------------------------#
def closingStatement():
    print("\n".join(["---------------------------------------------------------",
              "Thank you for using our Mass to Weight Calculator!",
              "Please use us for all your calculation needs."]))
    return

##---Main module--------------------------------------------------------------------------------#
#-----------------------------------------------------------------------------------------------#
def main():
    ##Introductory Statement
    intro()

    ##---Get Mass
    objectMass=getMass()

    ##Calculate Mass to Weight
    weight=weightConversion(objectMass)

    ##Compare results
    massToWeight(objectMass, weight)

    ##Closing Statement
    closingStatement()

main()

Hey everyone. My program is returning my else when my first condition of > 1000 is met in the massToWeight module and not sure why. The program didn't need modules, but wanted to practice working with modules in python.

Could someone please help?

Thank you,

Darryl

Aucun commentaire:

Enregistrer un commentaire