0% found this document useful (0 votes)
9 views12 pages

Assignment+5

Assignment 5 requires students to write three independent Python programs: one warm-up exercise and two individual projects. The warm-up involves collecting price values from the user and calculating subtotals, savings, and averages, while the main projects focus on tracking pilot training scores for the Rebel Alliance against the Galactic Empire. Each program must include user input validation and report averages and grades based on the collected data.

Uploaded by

jsc07302
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Assignment+5

Assignment 5 requires students to write three independent Python programs: one warm-up exercise and two individual projects. The warm-up involves collecting price values from the user and calculating subtotals, savings, and averages, while the main projects focus on tracking pilot training scores for the Rebel Alliance against the Galactic Empire. Each program must include user input validation and report averages and grades based on the collected data.

Uploaded by

jsc07302
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Assignment 5

For this assignment you will be writing 3 programs which should be


saved independently as their own ".py" file (1 warm-up problem and
2 "on your own" problems.) The filename you should use for each
program is outlined in the sections below. When you're finished you
should submit your programs using the 'Assignments' tool in
Brightspace.

In-class Warm-up Exercise


This is an in-class warm-up that you will be working on with your
classmates. Everyone should submit a copy of this warm-up
exercise, even if you completed it as a group. Please make sure to
include everyone's name at the top of your program! Warm-up
activities will be discussed in detail during our workshop session,
but they are worth a small # of points so don't forget to submit your
work.

Prompt the user to enter in a number of price values they wish to collect. Ensure that
the user enters a positive number when prompted.
Next, prompt the user for the desired # of price values. Ensure that each individual price
value provided is non-zero. Re-prompt the user as necessary.
When you are finished output the following:

1. The subtotal — the total cost of all positive prices collected

Assignment 5 1
2. The savings — the total discounts received, which is the sum of all the negative
numbers times -1 ) — note this should be a positive number.

3. The “grand total” — subtotal - savings

4. Additionally, display some statistics:

a. Average Item Price — The average of all the positive prices

b. Average Discount — The average of all the negative prices times -1 . Note this
should be a positive number.

Input assumptions:

Number of prices: a value of data type 'integer' within the range -2147483648 to
2147483647

Individual price value: a value of data type 'integer' within the range -2147483648 to
2147483647

How many prices would you like to collect? -5


Must be positive, try again

How many prices would you like to collect? 0


Must be positive, try again

How many prices would you like to collect? 6

Thanks, here we go!

Enter price #1: 100


Enter price #2: 90
Enter price #3: 80
Enter price #4: 0
Prices cannot be zero. They must be positive or negative.

Enter price #4: -10


Enter price #5: 70
Enter price #6: -20

---- Report ----


Subtotal: 340
Savings: 30
Grand Total: 310

Average Item Price: 85.00


Average Discount: 15.00

Assignment 5 2
Problem 1: Red Leader, Ready
This is a solo project. You may work as a group to help each other
out, but everyone should be writing a separate file on their own
computer. You will be doing yourself a HUGE disservice by not
working on this project by yourself! If you do share tips with one
another please be sure to include everyone's name at the top of
your program. Note that "sharing tips" does not mean "copied the
entire program" from someone else.

The Galactic Empire, led by Emperor Palpatine and his apprentice, Darth Vader, now
rule the galaxy. However, a small group of freedom fighters known as the Rebel
Alliance, is actively fighting to overthrow the Emperor.
The Rebel Alliance has acquired intelligence that the Empire is building a planet-
blasting super weapon, known as the Death Star. The Alliance’s first priority is to take
out this super weapon, as it poses a threat to their very existence.
To destroy this weapon, the Alliance need to train pilots, and track their progress.
Admiral Raddus has commissioned you to help write a program to track and rate pilots.
Pilots are grouped into “cohorts”, and trained and rated in the following activities:

1. Bombing Runs — The ability to bomb a target successfully

2. Space Dogfighting — The ability to defeat hostile fighters in 1:1 space combat

3. Maneuverability — The ability to maneuver a spacecraft in small spaces

Certain cohorts of pilots also need training on Hyperspace Navigation. However, not all
pilots need this training.

Your job is to write a program that lets the instructor of each cohort keep track of his or
her pilots. Your program should begin by asking the instructor for a few inputs that will
be used to control how the system works. The program should begin by gathering the
following information - all of this data must be validated:

Assignment 5 3
Number of pilots in the cohort: must be positive, no upper limit

Whether or not Hyperspace Navigation is a required activity for the pilots. Valid
inputs are “yes” or “no” in any combination of cases.

Number of training exercises for each of the training activities (Bombing Runs,
Space Dogfighting, Maneuverability, and perhaps Hyperspace Navigation). These
must be must be positive, no upper limit

Drop lowest score mode: Sometimes pilots get jittery. This option allows the
instructor to enable the system to drop the lowest score for each pilot in their cohort.
Valid inputs are "yes" or "no". Note: this mode should be “no” for any training activity
that has only one training exercises, and the user should be informed (see the
second example below for how this is to be done)

Next, prompt the instructor to enter in scores for each pilot. Ensure that the test score
values entered are within the range 0-100 (inclusive on both ends) This data must be
validated. Hint: you may need to use nested loops here! A while loop can be placed
inside of a for loop, if necessary.

If "drop lowest score mode" is turned on the system should figure out the lowest score
entered for each pilot, for each of the training activities, and report it to the user and
remove it from the grade calculation for the pilot.

You can assume that the user will enter integers when prompted (but they may not be
within the range you are expecting, hence the need for validation)

Once your program has collected all test scores for a pilot it should display that
student's average formatted to 2 decimal places. The program should also compute the
pilot’s letter grade for each training activity, using the following chart:

A: 90 or above

B: [80-90) - inclusive on the lower limit, exclusive on the upper limit

C: [70-80) - inclusive on the lower limit, exclusive on the upper limit

D: [63-70) - inclusive on the lower limit, exclusive on the upper limit

F: [0-63) - inclusive on the lower limit, exclusive on the upper limit

Assignment 5 4
The program should then move onto the next pilot. When all the grades for each pilot
have been calculated, the program should compute the overall average scores for each
training activity for the entire cohort.

Here's are a few sample runnings of your program (user input is highlighted):

How many pilots are in your cohort? 2


Are you training your pilots in HYPERSPACE NAVIGATION (yes/no)? No
How many training exercises will you have for BOMBING RUNS? 2
How many training exercises will you have for SPACE DOGFIGHTING? 3
How many training exercises will you have for MANUEVERABILITY? 4

Would you like to drop the lowest test for each pilot? (yes/no): no

Thanks, here we go!

*** Pilot #1 ***


Enter score for BOMBING RUNS exercise #1: -10
Score cannot be negative, try again.
Enter score for BOMBING RUNS exercise #1: 90.00
Enter score for BOMBING RUNS exercise #2: 80.00
Enter score for SPACE DOGFIGHTING exercise #1: 70
Enter score for SPACE DOGFIGHTING exercise #2: 90
Enter score for SPACE DOGFIGHTING exercise #3: 70
Enter score for MANUEVERABILITY exercise #1: 70
Enter score for MANUEVERABILITY exercise #2: 60
Enter score for MANUEVERABILITY exercise #3: 50.00
Enter score for MANUEVERABILITY exercise #4: 30

Pilot 1 received the following average scores:


BOMBING RUNS: 85.00 (B)
SPACE DOGFIGHTING: 76.67 (C)
MANUEVERABILITY: 52.50 (F)

*** Pilot #2 ***


Enter score for BOMBING RUNS exercise #1: 70
Enter score for BOMBING RUNS exercise #2: -10
Score cannot be negative, try again.
Enter score for BOMBING RUNS exercise #2: 50
Enter score for SPACE DOGFIGHTING exercise #1: 80
Enter score for SPACE DOGFIGHTING exercise #2: 90.00
Enter score for SPACE DOGFIGHTING exercise #3: 100
Enter score for MANUEVERABILITY exercise #1: 90
Enter score for MANUEVERABILITY exercise #2: 80.00
Enter score for MANUEVERABILITY exercise #3: 85
Enter score for MANUEVERABILITY exercise #4: 93.00

Pilot 2 received the following average scores:

Assignment 5 5
BOMBING RUNS: 60.00 (F)
SPACE DOGFIGHTING: 90.00 (A)
MANUEVERABILITY: 87.00 (B)

----- COHORT REPORT -----


Overall averages for the cohort
BOMBING RUNS: 72.50 (C)
SPACE DOGFIGHTING: 83.34 (B)
MANUEVERABILITY: 69.75 (D)

How many pilots are in your cohort? -3


Invalid input. Please enter a positive integer only.

How many pilots are in your cohort? 3


Are you training your pilots in HYPERSPACE NAVIGATION (yes/no)? lightsaber
Invalid input. Please enter "yes" or "no".

Are you training your pilots in HYPERSPACE NAVIGATION (yes/no)? Yes


How many training exercises will you have for BOMBING RUNS? -1
Invalid input. Please enter a positive integer only.

How many training exercises will you have for BOMBING RUNS? 3
How many training exercises will you have for SPACE DOGFIGHTING? 2
How many training exercises will you have for MANUEVERABILITY? 1
How many training exercises will you have for HYPERSPACE NAVIGATION? 1

Would you like to drop the lowest test for each pilot? (yes/no): yes

Note that the lowest score will NOT be dropped for the following activities because they o
nly have 1 training exercise each: MANUEVERABILITY, HYPERSPACE NAVIGATION

Thanks, here we go!

*** Pilot #1 ***


Enter score for BOMBING RUNS exercise #1: -10
Score cannot be negative, try again.
Enter score for BOMBING RUNS exercise #1: 90
Enter score for BOMBING RUNS exercise #2: 90
Enter score for BOMBING RUNS exercise #3: 95
Enter score for SPACE DOGFIGHTING exercise #1: 70
Enter score for SPACE DOGFIGHTING exercise #2: 90
Enter score for MANUEVERABILITY exercise #3: 70
Enter score for HYPERSPACE NAVIGATION exercise #1: 60

Pilot 2 received the following average scores:


BOMBING RUNS: 92.50 (A)
SPACE DOGFIGHTING: 90.00 (A)
MANUEVERABILITY: 70.00 (C)

Assignment 5 6
HYPERSPACE NAVIGATION: 60.00 (F)

*** Pilot #2 ***


Enter score for BOMBING RUNS exercise #1: 80.00
Enter score for BOMBING RUNS exercise #2: 91.00
Enter score for BOMBING RUNS exercise #3: 91
Enter score for SPACE DOGFIGHTING exercise #1: 50
Enter score for SPACE DOGFIGHTING exercise #2: 95
Enter score for MANUEVERABILITY exercise #3: 81
Enter score for HYPERSPACE NAVIGATION exercise #1: 75

Pilot 2 received the following average scores:


BOMBING RUNS: 91.00 (A)
SPACE DOGFIGHTING: 95.00 (A)
MANUEVERABILITY: 81.00 (B)
HYPERSPACE NAVIGATION: 75.00 (C)

*** Pilot #3 ***


Enter score for BOMBING RUNS exercise #1: 80
Enter score for BOMBING RUNS exercise #2: 70.50
Enter score for BOMBING RUNS exercise #3: 90.00
Enter score for SPACE DOGFIGHTING exercise #1: 85
Enter score for SPACE DOGFIGHTING exercise #2: 70
Enter score for MANUEVERABILITY exercise #3: 70
Enter score for HYPERSPACE NAVIGATION exercise #1: 80

Pilot 3 received the following average scores:


BOMBING RUNS: 85.00 (B)
SPACE DOGFIGHTING: 85.00 (B)
MANUEVERABILITY: 70.00 (C)
HYPERSPACE NAVIGATION: 80.00 (B)

----- COHORT REPORT -----


Overall averages for the cohort
BOMBING RUNS: 89.50 (B)
SPACE DOGFIGHTING: 90.00 (A)
MANUEVERABILITY: 73.67 (C)
HYPERSPACE NAVIGATION: 71.67 (C)

Input assumptions (the user could input any of the following):

Number of pilots in class: a value of data type 'integer' within the range
-2147483648 to 2147483647

Number of training exercises for each activity type: a value of data type 'integer'
within the range -2147483648 to 2147483647

Drop lowest score mode: any string of length 0 to length ~infinity

Assignment 5 7
Individual training exercise score: a value of data type 'integer' within the range
-2147483648 to 2147483647

Some hints:

You can assume that the user will enter integers for the # of pilots and # of training
exercises for each activity in the cohort, but you cannot assume the range of these
integers.

You can assume the user will enter floating point numbers when prompted for a test
score, but you cannot assume the range of these floating point values.

To collect pilot data you should probably begin by constructing a "for" loop to iterate
over all pilots in the class

Once you're inside of this "for" loop you will probably need nested loops to handle
inputting the scores for each activity for a particular pilot. Remember there are only
4 activities (and one of them is based on whether “Hyperspace Navigation” is
enabled).

Big hint: Try to get your program to work first without any data validation. You can
add this in later once you figure out the general structure of the program.

Remember the difference between "for" and "while" loops! "for" loops are used
when you want to iterate over a know # of items, and "while" loops can be used to
keep the user "caught" indefinitely until they fulfill a particular condition. You will
probably need to use a combination of these loops to solve this problem.

Accumulator variable placement is a critical part of this program. Remember that


your accumulators should be placed outside of the loop they are being used in so
that they don't get overwritten each time the loop re-iterates. But some of your
accumulators may need to be overwritten (i.e. each student probably needs their
points earned to start at 0) - placement of some accumulators may be different
depending on the purpose of each variable.

This program should be named as follows: LastNameFirstName_assign5_part1.py (for


example, PatilMihir_assign5_part1.py )

If you shared any code or helped out a group member with this project please be sure to
give credit to that person by including their names in the commented header of your
program.

Assignment 5 8
Problem 2: For the Republic — Court
Reform
After the destruction of the second Death Star and the defeat of the Galactic Empire, a
new government, called the “New Republic” was formed. This New Republic hoped to
engage in large scale reforms in an effort to improve fairness and equity throughout the
galaxy.
Leia Organa Solo, a senator in the new Galactic Senate, had her eyes set on reforming
the Supreme Court of the Republic. The Supreme Court consists of 2 associate justices,
and one chief justice, for a total of 3 justices. Each of these justices, including the chief
justice are appointed by the Supreme Chancellor (the executive of the New Republic),
and confirmed by the Galactic Senate, and each justice serves a lifetime appointment.
However, this model leads to significant inequities in which Supreme Chancellor gets to
appoint which justices. For example, if a significant number of justices pass away or
retire during the term of a particular Supreme Chancellor, that Supreme Chancellor has
a disproportionate sway in shaping the the makeup of the highest court in the galaxy.
Senator Organa Solo’s proposal to resolve this is to do the following:

1. Randomly choose the all 3 associate justices from the 10 appellate court justices
that exist (appellate courts very high courts in the galaxy, only lower than the
supreme court itself)

2. The senior-most of the individuals chosen is named the chief justice. If there’s a tie
in seniority, one of the selected individuals involved in the tie is picked at random as
the chief justice.

This process will be repeated for every case that comes before the Supreme Court of
the Republic. This means, for example, that if there are 5 cases that come before the
Supreme Court every year, 5 different combinations (of 3 justices each) will be chosen
at random. Note that a single individual can serve as a justice for multiple cases.
Senator Organa Solo has commissioned you to write a program to do demonstrate this
proposal. To do this, your program will have to collect the following information, and
validate each input, like in Problem 1.

1. Number of cases on the docket (integer)

2. Names of all the appellate court justices (string)

Assignment 5 9
3. The year each of the appellate court justices started their tenure (integer)

Then you must print out the random combinations of courts for each case.

Here is a sample output of a run:

How many cases are there?: -10


Invalid number of cases, please enter a positive integer.
How many cases are there?: 5

Enter Info for Appellate Court Judge #1


Name: Bilbo Baggins
Start Year: -1102
Invalid year, please enter a positive integer.
Start Year: 1102

Enter Info for Appellate Court Judge #2


Name: Alexander Hamilton
Start Year: 1100

Enter Info for Appellate Court Judge #3


Name: Peggy Carter
Start Year: 1109
Enter Info for Appellate Court Judge #4
Name: Leslie Knope
Start Year: 1121

Enter Info for Appellate Court Judge #5


Name:
Invalid input. Please enter at least one character for a name.
Name: Jessica Jones
Start Year: 1118

Enter Info for Appellate Court Judge #6


Name: Dante Basco
Start Year: 1115

Enter Info for Appellate Court Judge #7


Name: James Kirk
Start Year: 1113

Enter Info for Appellate Court Judge #8


Name: Hermione Granger
Start Year: 1113

Enter Info for Appellate Court Judge #9


Name: Christopher Pike
Start Year: 1114

Enter Info for Appellate Court Judge #10

Assignment 5 10
Name: Aayla Secura
Start Year: 1110

*****************
** CASE PANELS **
*****************

** Case 1 Justices **
Chief Justice: Peggy Carter
Associate Justices: Aayla Secura, Dante Basco

** Case 2 Justices **
Chief Justice: Hermione Granger
Associate Justices: Christopher Pike, James Kirk

** Case 3 Justices **
Chief Justice: Alexander Hamilton
Associate Justices: Leslie Knope, Jessica Jones

** Case 4 Justices **
Chief Justice: Bilbo Baggins
Associate Justices: Peggy Carter, Dante Basco

** Case 5 Justices **
Chief Justice: James Kirk
Associate Justices: Leslie Knope, Jessica Jones

Input assumptions (the user could input any of the following):

Number of cases: a value of data type 'integer' within the range -2147483648 to
2147483647

“Start Year”: a value of data type 'integer' within the range -2147483648 to
2147483647

“Name”: any string of length 0 to length ~infinity

Some hints:

You can always assume the user will enter an integer when prompted, but you will
need to validate it so that it falls within the desired range (1 or larger)

Note that 0 is technically a valid year. You should, however, validate for negative
years.

Assignment 5 11
Remember that it is possible for all 3 selected justices to have the same start year.
In the case the chief justice will be picked at random amongst all 3 chosen justices.

Remember that an individual can serve on multiple cases.

Remember that all the individuals serving on a single case must be unique. For
example, a single person cannot be both an associate justice and a chief justice —
each position must be occupied by someone unique (associate justice 1, associate
justice 2, and chief justice)

This program should be named as follows: LastNameFirstName_assign5_part2.py (for


example, PatilMihir_assign5_part2.py )
If you shared any code or helped out a group member with this project please be sure to
give credit to that person by including their names in the commented header of your
program.

Assignment 5 12

You might also like