Contents

  1. average2.py
  2. input_demo.py

average2.py 1/2

[
top][prev][next]
# Finds the average of two numbers
# by CS111 class

print("This program finds the average of two numbers.")
print()

# assign two variables
num1=float(input("Enter the first number: "))
num2=float(input("Enter the second number: "))

# sum those two variables
mySum = num1 + num2

# divide those variables by two
myAverage = mySum/2

# display the output
print("The average of", num1, "and", num2, "is", myAverage)

input_demo.py 2/2

[
top][prev][next]
# Demonstrate numeric and string input
# by Sara Sprenkle for CS111

color = input("What is your favorite color? ")
print("Cool!  My favorite color is _light_", color, "!")

rating = eval(input("On a scale of 1 to 10, how much do you like Ryan Gosling? "))
print("Cool!  I like him", rating*1.8, "much!")


Generated by GNU Enscript 1.6.6.