Contents

  1. average3.py
  2. demo_str.py
  3. escape_sequence.py
  4. scale.py

average3.py 1/4

[
top][prev][next]
# This program will compute the average of 3 numbers
# By CSCI 111

print "This program will compute the average of three numbers\n"

# get three numbers from the user
x=input("Please enter the first number: ")
y=input("Please enter the second number: ")
z=input("Please enter the third number: ")


# average the three numbers
total = (x+y+z)
average = float(total)/3

# display the output
print "The average of", x, ",", y, "and", z, "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=0
SCALE_MAX=100

prompt = "On a scale of " + str(SCALE_MIN) + " to " + str(SCALE_MAX) + ", how much do you like Matt Damon? "

# ask once, with wise crack
rating = input(prompt)
print rating,"?!?  That's more than I do."

# ask again, with wise crack
rating = input(prompt)
print "Nah,", rating, "is much too low."


Generated by GNU enscript 1.6.4.