Tuesday, October 2, 2018

More python and loops:

Conversion.py

#conversion.py
# A program that converts celsius to fahrenheit
# by steve

#steps
#look up conversion formula
#get the celsius from input
#apply the equation (9/5)* c + 32)
# display the results

def main():
    print ("This program converts Celsius temperatures to Fahrenheit.")
    celsius=eval(input("Please enter a celsius temperature: "))
    fahrenheit = 9/5 * celsius + 32
    print("The fahrenheit temperature is", fahrenheit)

main()

Loops.py

# look at counted loops

def main():
    sum=0.0
    loops = int(input("How many numbers do you want to enter: "))
    for i in range(loops):
        number = int(input("Enter an integer"))
        sum =sum + number
    average=sum/loops
    print("the total is:",sum)
    print("the average is:",average)

main()

No comments:

Post a Comment