Contents

  1. arith_and_assign2.py
  2. arith_and_assign.py
  3. average2.py

arith_and_assign2.py 1/3

[
top][prev][next]
# Demonstrates arithmetic operations and assignment statements.
# This program has one less assignment statement but the last print statement
# is more complicated, which, as our programs grow, makes it harder to debug programs.
# This works but is not the way we will typically write programs.
# by Sara Sprenkle

x = 3
y = 5

print("x =", x)
print("y =", y)

# alternatively:
print("x*y =", x*y)

arith_and_assign.py 2/3

[
top][prev][next]
# Demonstrates arithmetic operations and assignment statements
# by Sara Sprenkle

x = 3
y = 5

print("x =", x)
print("y =", y)

result = x * y
print("x*y =", result)

average2.py 3/3

[
top][prev][next]
# Finds the average of two numbers
# by CS111 class

print("This program computes the average of two numbers.")

# assign values to two numbers

num1=2.5
num2=-2.5

# find the average of the two numbers:
# add the two numbers together and then divide by 2

average=(num1 + num2)/2

# display the result
print("The average of", num1, "and", num2, "is", average)

Generated by GNU Enscript 1.6.6.