Tuesday, October 23, 2018

functions

First Functions

#break into seperate
# each function should do one
 def Hello():
     print('Hello all you martians')

 def main():
     Hello()

 main()

Second Functions

def getName():
    name=input("enter your name")
    hello2(name)

def getAge():
    age=int(input("Enter your age: "))
    return age

def hello2(name):
    a=getAge()
    print ("Hello,",name,"you are",a,"years old")

def main():
    getName()

main()

Gas Mileage

#miles, gallons
#get inputs, calculate the mileage, output
def getMiles():
    miles=int(input("Enter the total miles: "))
    return miles

def getGallons():
    gallons=int(input("Enter the total gallons: "))
    return gallons

def calculateMileage():
    m=getMiles()
    g=getGallons()
    mpg=m/g
    output(m,g,mpg)

def output(miles, gallons, milesPerGallon):
    print ("You drove",miles,"miles.")
    print ("You put in",gallons,"gallons of gas")
    print("You had",milesPerGallon, "MPG.")

def main():
    calculateMileage()

main()

Meters to Feet

#get feet, calulate, output
def getFeet():
    feet=float(input("Enter the feet: "))
    return feet

def calcMeters():
    feet=getFeet()
    meters=feet / 3.2
    display(feet, meters)

def display(feet, meters):
    print(feet, "equals", meters,"meters")

def main():
    calcMeters()

main()

No comments:

Post a Comment