[Tutor] First Program!
Wesley J. Chun
Sun, 6 Feb 2000 14:24:13 -0800 (PST)
> Date: Sun, 6 Feb 2000 21:56:17 +0100
> From: Gerrit Holl <email@example.com>
> jiggity wrote on 949840439:
> > I just learned Python and am wondering what type of program would be the easiest to try to write. I am not looking for anything to fancy. Just something to test what I can do.
> Write a program that takes a random number and asks the user to input
> a number. If the user guesses to low, say so. If the user guesses to
> high, say so. Count the number of turns the user needs to guess the
> number, and tell him when he guessed the number.
gerrit's example sounds like a worthy project.
here are some that like to give to my students:
1. a. write a program to take a year (either as
user input via raw_input) or hard-coded (not
as fun) and output whether it is a leap year.
b. then split up your program to put the leap
year logic inside a function and have the main
part of your program call just the function
for a quick yes/no (1/0) result, then push the
output to the screen.
recall that a leap is divisible by 4, but not
100, unless *that* is also divisible by 400.
in other words, although 1800 and 1900 are
divisible by 4, they are not divisible by 400,
hence are not leap years. 2000 is a leap year;
the next century leap yea won't come up again
2. a. write code that will take a string and invert
it. in other words, create another string that
is the same as the original string only going
b. now either upgrade your program or come up
with another way to: take two strings and de-
termine if they are palindromic (same backwards
as forwards), i.e. bob, eve, kayak, etc.
c. upgrade your program again to ignore spaces,
case, and punctuation, so that it recognizes
sentences like: "Madam, I'm Adam." or "A man,
a plan, a canal... Panama!"