Hello everyone,
I've been hanging out on the fringes for a while. I just started
teaching python to a group of ten students, in a small school that has
never offered programing before. Thus far, it's very exciting to see
the students be spurred on by quick success they have with the language.
Now I'm getting to the point of trying to come up with problems
(programs) that are challenging for the students but let them use the
tools they have thus far. I'm mostly following the introduction scheme
of "How to think like a computer programmer - Python version". I saw
that a while back there was some thought of collecting a group of
exercises for class use. My first thought, since we just got finished
with functions and logic statements, was to work on a basic calculator
and then maybe a hangman kind of game.
So I'm asking (again kind of) if there are any resources for beginner
problems to be solved through programming - realizing that most of these
kids are not college mathematicians. Second, I took my first try at the
calculator program and it works mostly. Remember, I'm just learning
also... the old "keep a day ahead" kind of teaching.
Second, I am opening myself up and asking for thoughts on the simple
calculator program I wrote. I'll include the code below, and would like
to get any comments you have to offer. If I'm going to use it as an
example, I want to make sure it's a decent one.
Thanks for any help and thoughts you can give. This is a new venture,
and I want the students to learn good habits, be successful, and
encourage the administration to continue this offering.
Sincerely,
Ryan Booz
Tech Coordinator
Belleville Mennonite School
---------------- Calculator program ----------------------
# This is a simple Calculator for our Python Class
#
# First each of the functions for manipulating the two numbers is
defined
def addition(x,y):
global new
new = x+y
print "The sum of",x,"and",y,"is",new
def subtraction(x,y):
global new
new = x-y
print "The difference of",x,"and",y,"is",new
def multiply(x,y):
global new
new = x*y
print "The product of",x,"and",y,"is",new
def divide(x,y):
global new
new = x/y
print "The qoutiant of",x,"and",y,"is",new
#
# This is the first function that actually asks for the first two
numbers. It is called only once.
# Once the two numbers are given, the function calls the decision making
function 'desc()'
#
def new_num():
x=input("What is the first number you would like to use? ")
y=input("What is the second number you would like to use? ")
desc(x,y)
#
# The inital input function calls this function which simply determins
what the user
# wants to do. Then if calls the correct manipulation function which
actually does the calculation
#
def desc(x,y):
compute=raw_input("Would you like
to:\nAdd(a)\nSubtract(s)\nMultiply(m)\nor Divide(d)")
calc(x,y,compute)
#
# Here's the function that calls the appropriate calculation function
# ***Important to notice***
# Once each calculation is done, that part of this function calls the
last
# function which asks if the user wants to do something further to the
new number
#
def calc(x,y,compute):
global new
if compute=="a":
addition(x,y)
sec_num(new)
elif compute=="s":
subtraction(x,y)
sec_num(new)
elif compute=="m":
multiply(x,y)
sec_num(new)
elif compute=="d":
divide(x,y)
sec_num(new)
else:
print "You need to choose one of the four options!"
desc()
#
# This is the function that asks if the user wants to do anything more
with the new number
# It then calls the decision function again if they answer yes
#
def sec_num(new):
choice=raw_input("Do you want work with a new second number (y or n)?
")
if choice == "y":
second_num=input("What is the new number you would like to work with?
")
desc(new,second_num)
else:
return
# This is where the program actually starts. Once it gets going, it all
runs between the
# functions
print "This is a simple calculator. You will input two numbers and then
have the\ncomputer add, subtract, multiply, or divide the two
numbers.\nThen you will have a chance to continue your calulations"
print
new_num()
# When they get a chance to do another calculation, if they answer 'no'
# then the program exits the functions and prints the following line
print
print "Thanks for using the program!"