Contents

  1. average2.py
  2. input_demo.py
  3. int_input.py

average2.py 1/3

[
top][prev][next]
# This program calculates and displays the average of two numbers
# by CS111 class

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


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 = float(input("On a scale of 1 to 10, how much do you like Zendaya? "))
print("Cool!  I like her", rating*1.8, "much!")

print(rating)

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.