Contents
- average2.py
- input_demo.py
- int_input.py
average2.py 1/3
[top][prev][next]
# Finds the average of two numbers
# by CS111 class
print("This program computes the average of two numbers.")
# assign values to two numbers
num1 = eval(input("What is your first number? "))
num2= eval(input("What is your second number? "))
# find the average of the two numbers:
# add the two numbers together and then divide by 2
average=(num1 + num2)/2
# display the result
print("The average of", num1, "and", num2, "is", average)
input_demo.py 2/3
[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 Zendaya? "))
print("Cool! I like her", rating*1.8, "much!")
int_input.py 3/3
[top][prev][next]
# Requiring an integer as input.
# by Sara Sprenkle
str_age = input("Enter your age: ")
age = int(str_age)
# this will throw an exception if the str_age is not an int.
# We don't know how to handle exceptions yet.
Generated by GNU Enscript 1.6.6.