Contents
- ./average2.py
- ./input_demo.py
- ./int_input.py
- ./name.py
./average2.py 1/4
[top][prev][next]
# This program calculates and displays the average of two numbers
# by CS111 class
./input_demo.py 2/4
[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/4
[top][prev][next]
# Requiring an integer as input.
# by Sara Sprenkle
str_age = input("Enter your age: ")
age = int(str_age)
# the above code will throw an exception if the str_age that is input
# is not an int. We don't know how to handle exceptions yet, so
# the program will end with an error.
print("You look good for", age)
./name.py 4/4
[top][prev][next]
# Introduction - and demonstrates getting user input
# by Sara Sprenkle for CS111
name = input("What is your name? ")
print("Nice to meet you,", name, "!")
Generated by GNU Enscript 1.6.5.90.