Contents

  1. average3.py
  2. debug_practice.py
  3. demo_str.py
  4. escape_practice.py
  5. input_demo.py

average3.py 1/5

[
top][prev][next]
# In-class Exercise: Average Three Numbers
# By CS111-02

# Prompt the user for input
num1=input("Enter the first number: ")
num2=input("Enter the second number: ")
num3=input("Enter the third number: ")

# Total the three numbers
total = num1 + num2 + num3

# Divide the total of the numbers by 3
avg = total/3

# Display output to the user
print "The average is", avg

debug_practice.py 2/5

[
top][prev][next]
# Program to exercise our debugging skills
# Contains one syntax error and two runtime exceptions
# By Sara Sprenkle, 09/14/07

x = 10
y = 7
z = x + v

a = 15
c = 8
b = a - 7
b -= c

z = c/b

print The answer is ", z

demo_str.py 3/5

[
top][prev][next]
# Demonstrate long strings, escape sequences
# by Sara Sprenkle, 09/14/07
#

string = """This is a long string.
Like, really long."""

print string

print "To print a \\, you must use \"\\\\\""


print "I could print more after this...",

print "See?"

escape_practice.py 4/5

[
top][prev][next]
# Practice with escape sequences
# CS111-02
#


# Print: 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\'."

# Print: I said, "How are you?"
print "I said, \"How are you?\""
print 'I said, \"How are you?\"'

input_demo.py 5/5

[
top][prev][next]
# Demonstrate numeric and string input
# by Sara Sprenkle for CS111 on 9/12/07
#

color = raw_input("What is your favorite color? ")
print "Cool!  My favorite color is _light_", color, "!"

scale = input("On a scale of 1 to 10, how much do you like Matt Damon? ")
print "Cool!  I like him", scale*1.8, "much!"   # always likes him more

# x = input()

Generated by GNU enscript 1.6.4.