Computer Science Department |
CSCI 135 |
Part 1: If Statements
The first part of your assignment is to create
a program that calculates the cost of mailing a package.
You should name your program Shipping.py.
Given the weight of the package as a command line parameter, you need to calculate just how much it would cost to ship based on the following rules:
The cost of sending a package by an express delivery service is $15.00 for the first two pounds, and $5.00 for each pound or fraction thereof over two pounds. If the package weighs more then 70 pounds, a $15.00 excess weight surcharge is added to the cost. No package over 100 pounds will be accepted.
Write a program that accepts the weight of a package in pounds as a command line argument and computes the cost of mailing the package. Be sure to handle the case of overweight packages.
Some test input cases are shown below:
For the input "135" your program would print:
For the input "75" your program would print:Package is over 100 pounds and cannot be shipped.
It will cost you $395.0 to ship your package.
For the input "60" your program would print:
It will cost you $305.0 to ship your package.
My program's output isn't quite the same as yours for the example input above. Is that okay? Not really. Learning to program involves a lot of attention to detail. You should strive to exactly match our example outputs. There will be plenty of opportunity for creativity in future assignments and extra-credit levels. The assignment page is the "contract", sticking to the exact program specification will make grading easier for the TA, and that is good for all involved!
Why do I only get one decimal place in my output when I really want two? We will look at how to format output later on in the semester. For now we can just live with some less than perfect output.
How do I declare a constant?
How do I round a floating point number upward?MAX_WEIGHT = 100
I accidently named my program Shipper or shipping or ... Is that okay? No. This will break our grading script. This is a surefire way to make your TA grumpy. Plus it is really easy to fix. You can either choose to "Save As" the correctly named file in the Idle editor, or you can right click on the file in File Explorer and choose "Rename".import math ... roundedUpNumber = math.ceil(previousNumber)
Part 2: If Statements
Create a program Lottery.py that takes two command line arguments.
Both numbers should be integers between 1 and 10, and they represent guesses on a lottery pick.
Your program should generate two random numbers between 1 and 10, and compare them to the command line input.
You are to use a nested if statement to determine whether the command line picks are winning numbers.
First, print out what the two randomly generated lottery numbers were, then what the command line arguments (the user's picks) were. Then, if there is no match, print out "Sorry, no match". If one number matches, print out "You matched one number! You win $100!!" Finally, if both number match print out "You matched both numbers! Congratualations! You win $1000!!"
Here is an example output given that no numbers matched:
The lottery numbers were 7 and 3. Your picks were 2 and 8. Sorry, no match.
Here is an example output where 1 number matched:
The lottery numbers were 4 and 2. Your picks were 2 and 8. You matched one number! You win $100!!
Here is an example output given that both numbers matched:
How do I generate a random number between 1 and 10? Use the following line to get a random number in that range:The lottery numbers were 2 and 6. Your picks were 6 and 2. You matched both numbers! Congratulations! You win $1000!!
Sometimes I get two random numbers that are the same. Is this OK?Yes, that can happen sometimes.import random ... lotteryNumber1 = random.randint(1, 10)
Part 3: Lots of Conditions
Create a program Zodiac.py that determines the Chinese zodiac sign given a year of birth.
The year of birth should be an integer. Use if statements in your program to determine which sign to output.
The rules for the Chinese zodiac signs are as follows: It is based on a 12 year cycle. If you were born in a year that is evenly divisible by 12, your sign is Monkey. If your year of birth, when divided by 12, has a remainder of 1, your sign is Rooster. Here is the entire list:
0: Monkey 1: Rooster 2: Dog 3: Pig 4: Rat 5: Ox 6: Tiger 7: Rabbit 8: Dragon 9: Snake 10: Horse 11: Sheep
So for example, for the input "1975" your program would print:
You were born in the year of the Rabbit.
Grading Each of the three programs is worth 10 points each, for a total of 30 points. For each program, you will be graded according to the following criteria:
Grade Item | Shipping | Lottery | Zodiac | Points Earned |
---|---|---|---|---|
Program Compiles and Runs | 4 | 4 | 4 | |
Header Comment | 2 | 2 | 2 | |
Program Runs Correctly | 4 | 4 | 4 |
Page last updated: August 16, 2021