Contents

  1. ./input_demo.py
  2. ./int_input.py

./input_demo.py 1/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 = 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 2/2

[
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.5.90.