Contents

  1. arith_practice.py
  2. average3.py
  3. scale.py

arith_practice.py 1/3

[
top][prev][next]
# Arithmetic practice
#
#

print 5+3*2
print 2 * 3 ** 2
print -3 ** 2
print 2 ** 3 ** 2

average3.py 2/3

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

# Remember: could do type conversion instead of 3.0
# Need to make total a float, somehow

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

scale.py 3/3

[
top][prev][next]
# Demonstrate use of constants, string concatenation
# by Sara Sprenkle for class on 09/14/07
#

SCALE_MIN="1"
SCALE_MAX="100"

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

scale = input(prompt)

print scale,"?!?  That's more than I do."

scale = input(prompt)

print "Nah,", scale, "is much too low."

Generated by GNU enscript 1.6.4.