Starting from:

$30

A2: Variables, Boolean logic, Conditionals

CSCI 141

A2: Variables, Boolean logic, Conditionals

This assignment has 2 parts. For the first part please answer the questions on Canvas assigned
for this homework, and for the second portion you will complete a single programming task.

1 Questions: 16 points
Please answer the questions available on Canvas. The questions on Canvas have been configured
so that there is no time limit, but you have only 2 attempts to submit your answers. The score
that is recorded in Canvas is the score that is the latest (most recent submission) of your
attempts.
2 Coding Task: 25 points
Suppose that you are a programmer for a game development company called Fungi. The text
adventure game being prepared for launch involves a character meandering through the forest,
during which they find and pick up mushrooms.
Your task is to write code for a portion of the game in which the role-playing character encounters a chef who wants to exchange some of the gathered mushrooms for rubies. The chef
exchanges mushrooms for rubies according to her secret formula (explained below).
The chief game designer has given you the below pseudocode that explains the mechanics that
your python program should implement. The chief software engineer has also instructed you
to use no more than 10 if keywords.
• Prompt the player to specify how many shiitake mushrooms were found and picked up
• Prompt the player to specify how many portobello mushrooms were found and picked up
• Include a narrative of how the player is meandering through the forest
1
• The chef asks the player how many of the shiitake mushrooms they’d like to trade
• The chef asks the player how many of the portobello mushrooms they’d like to trade
– If the player specifies that they want to trade more mushrooms (of either kind) than
have been collected, the chef ends the conversation (the program ends; it should not
throw an error).
– If the player specifies to trade a total of zero mushrooms (i.e., the sum of both
mushroom types), the chef ends the conversation (the program ends; it should not
throw an error).
– If the player wants to trade their mushrooms, then the chef will offer rubies according
to the following exchange rules (the chef’s secret formula):
Number Shiitake Player
is Willing to Trade
Number Portobello
Player is Willing to
Trade
Rubies Offered by Chef
Fewer than 10 Fewer than 5 Twice the number of Shiitake
offered for trade
Fewer than 10 5 or more Three times the number of
Portobello offered for trade
Multiple of 12 but NOT
a multiple of 24
20 or more Four times the number of Portobello offered for trade
Multiple of 12 but NOT
a multiple of 24
Fewer than 20 The number of Portobello offered for trade
A number of Shiitake
mushrooms different
than any of the 4 above
choices
Any Five times the number of Shiitake offered for trade
• The chef should ask the player if they want to make the exchange. If the player enters y,
yes, or Yes, the program should output the number of rubies that the player walks away
with, as well as the number of portobello and shiitake mushrooms that the player retains.
Otherwise, the program should output the number of portobello and shiitake mushrooms
the player walks away with.
Two sample invocations of the program are shown in Figure 1:
2
Figure 1: Sample Outputs
If you proceed with computer science you’ll learn about more formal testing techniques. For
the time being, use the below table for sample inputs and outputs of the program to make sure
that your code is working correctly. Note that these sample inputs are not an exhaustive test
suite. Your code will be graded on a different set of tests from the ones given below, so you
can’t count on these tests finding all possible mistakes. You should test your program on your
own combinations of inputs, making sure that you have tried out all possible paths that your
code might take.
Shiitakes
Found / Willing to Trade
Portobellos
Found / Willing to Trade
Chef Offers Accept? Player’s Final Shiitake/Portobello/Rubies
10/5 30/22 66 rubies Yes 5/8/66
100/0 40/5 15 rubies Yes 100/35/15
10/10 5/6 Chef runs away NA NA
10/10 6/5 50 rubies No 10/6/0
20/0 0/0 Unwilling to trade NA NA
13/12 9/8 8 rubies Yes 1/1/8
Submission
Submit a file called fungiExchange.py to Canvas containing your implementation of the program, and complete the questions on Canvas. Fill out the A2 Hours quiz on Canvas with an
estimate of the number of hours you spent working on both parts of this assignment.
3
Rubric
Canvas questions 16 points
Top of python file has comments, including name, date, and description 1
The program correctly prompts for the mushroom input 2
The ruby and remaining mushroom counts are correct after making a trade 7
The remaining mushroom counts are correct when the trade is not made 2
The program responds correctly if the player specifies they want to trade 0 3
The program responds correctly if the player wants to trade more mushrooms
than have been picked up
3
The program uses no more than 10 if keywords 5
The code is commented adequately and variable names are appropriately named 2
Total 41 points
3 Challenge Problem
The A2 challenge problem is worth 1 point of extra credit: Write a program that prompts
the user for three integers, and prints the median and mean of the three integers. Do not use
any built-in or external libraries (i.e., your program should not have any import statements).
Upload your solution as threestats.py
4

More products