This homework must be submitted by 8pm on the due date to get any credit.
In this homework, we will be doing a series of exercises designed to make you practice using variables, expressions, and if statements. Each one of these should be in a separate python file. For this assignment, you may assume that all the input you get will be of the correct type.
Please do not use the math library for this assignment.
For this assignment, you'll need to follow the class coding standards, a set of rules designed to make your code clear and readable. The class coding standards are here
- part1.py Write a program that prints the numbers from 1 to 100, one per line. However, when a number is divisible by three, it should print the string "foo" INSTEAD of the number. If it is divisible by 5, you should print "bar". If it is divisible by both, you should print "baz".
- part2.py Create a program that takes an input from the user and prints out whether or not it is prime. (For our purposes, neither one or zero should be prime)
- part3.py Write a program that creates a box made of the * character. The program should ask for the width and height of the box (width first, then height). The width and height will always be positive. The inside of the box should not be filled in. For example:
Please enter the width of your box: 3
Please enter the height of your box: 5
Please note that on your terminal, it may not look exactly like a square. There should always be (width - 2) blank spaces on the lines inside the square.
- part4.py Write a program that prints out a triangle made of the * character. It should take an input from the user asking how tall the triangle should be. For example:
Please enter the height of your triangle: 5
- part5.py For this part, you're going to create a program that takes modulous without using the modulous operator. You should take two numbers from the user, a and b, and compute a % b without using the modulous operator or division. It should work even if a < b. You do not need to worry about cases where either number is negative.
- part6.py Create a program that does input valdiation. Prompt the user for a positive number. If they enter one, simply print it back out. If they enter a negative number (or zero), you should continue to ask them for a positive number until one is entered. You can assume the input will always be a number.
Please enter a positive number: -1
Please enter a positive number: -20
Please enter a positive number: 2
Your number was 2
When you've finished your homework, use the submit command to submit the
You must be logged into your account and you must be in the same directory
as the file you're trying to submit.
At the Linux prompt, type
submit cs201 HW3 part1.py part2.py part3.py part4.py part5.py part6.py
After entering the submit command shown above, you should get a
confirmation that submit worked correctly:
If not, check your spelling and that you have included each of the
required parts and try again.
You can check your submission by entering:
submitls cs201 HW3
You should see the name of the file that you just submitted, in this case
parts 1 through 5.