|
CS 140: Introduction
to Computer Programming
HOMEWORK #2
due Friday, Sept 14 by
5:00pm
Guidelines
for completing and submitting homework
Refer to the first two paragraphs on the Grading Info
page for all the details. Briefly,
you may not collaborate with your
classmates while writing homework
programs. However, you may certainly
consult Spencer on Thursday evenings or
Dr. V on Friday afternoons (except
2:00-2:45) as you create your
programs. Other QRC mentors may also
be able to help out, depending on their
experience with Python. Once you
have completed your program, or made as
much progress as possible, email your
program as an attachment to svandervelde@stlawu.edu.
Assignment
To begin, create a new document in Komodo
and include these comments at the top
# Your full
name
# Homework #2, Sept 14, 2012
# Individuals providing assistance,
if any
Then save your file using the format LastNameHW2.py.
Now write a program that performs the
three tasks listed below.
- It should first print the full lyrics to
the song "100 Bottles of Beer on the
Wall." In other words it should print
one hundred lines of output, beginning with
100 bottles
of beer on the wall, 100 bottles of
beer. Take one down, pass it
around, 99 bottles of beer on the
wall.
99 bottles of beer on the wall,
99 bottles... and so
on.
Optional:
for a bit of extra credit, include if else
statements within your for loop that makes
the last line print correctly. (Not as
1 bottles of
beer...)
- Next your program should ask the user to
enter a three-digit number and assign the
name num
to this value. Then print a list of all
positive integers from 1 to num
that divide evenly into num.
(Recall that we can use remainders to check
this, so the %
symbol will help.) Print your list on a
single line, not one number under another.
- Let us say that a two-digit number is suave
if it is equal to the sum of the squares of
its digits plus the product of its
digits. For instance, 63 is suave
because if we add together 6 squared plus 3
squared plus 6 times 3 we get 36+9+18, which
bring us right back to 63. Write code
that finds all suave numbers.
|
|
|