Contents
- average3.py
- demo_str.py
- escape_sequence.py
- scale.py
average3.py 1/4
[top][prev][next]
# This program averages three numbers given in input
# By CS111, 1.19.2011
print "This program will calculate the average of three numbers."
# Get the three numbers
num1=input("Enter first number: ")
num2=input("Enter second number: ")
num3=input("Enter third number: ")
# Calculate average
# Sum up the numbers
total = num1+num2+num3
# Divide the sum by 3
average = float(total)/3
# Display the output
print "The average of ", num1, ",", num2, "and", num3,
print "is", average
demo_str.py 2/4
[top][prev][next]
# Demonstrate long strings, escape sequences
# by Sara Sprenkle
string = """This is a long string.
Like, really long.
Sooooo loooooong"""
print string
print "To print a \\, you must use \"\\\\\""
print "I could print more after this...",
print "See?"
escape_sequence.py 3/4
[top][prev][next]
# Practice with escape sequences
# CS111
# Display To print a tab, you must use '\t'.
print "To print a tab, you must use a '\\t'."
print 'To print a tab, you must use a \'\\t\'.'
# Display I said, "How are you?"
print "I said, \"How are you?\""
print 'I said, "How are you?"'
scale.py 4/4
[top][prev][next]
# Demonstrate use of constants, string concatenation
# by CS111
#
SCALE_MIN=1
SCALE_MAX=1000000
DIVIDER_LENGTH=100
prompt = "On a scale of " + str(SCALE_MIN) + " to " + str(SCALE_MAX)+ ", how much do you like Matt Damon? "
divider="-"*DIVIDER_LENGTH
print divider
# ask once, with wise crack
rating = input(prompt)
print rating,"?!? That's more than I do."
print divider
# ask again, with wise crack
rating = input(prompt)
print "Nah,", rating, "is much too low."
print divider
Generated by GNU enscript 1.6.4.