TASK 1
[Testing: Variables and expression, strings, input, and outputting formatted text]
Function task1 should do the following:
- Prompt the user to input their first name.
- Prompt the user to input their last name.
- Prompt the user to ask them how many hours they work a week.
- Prompt the user to ask them what is their hourly wage.
- Based on the information obtained from (1)-(4), print out the following:
Employee: LASTNAME, Firstname You should trip off all white -spaces.
$XXXX.XX Monthly salary (gross) Last name should be printed with All capitals letters.
-$YYYY.YY 25% Tax deduction First name should be printed with first letter capital, the rest lower case.
$ZZZZZ.ZZ Monthly salary (net) Monthly salary (gross) is hours per week * hourly wage * 4
Tax deduction is monthly salary * 0.25
Monthly salary (net) is your (gross) salary minus the taxes. This is the amount
you have after taxes.
All amounts should be printed with 2 decimal places.
Example:
Red text is entered by user. Notice the extra spaces for items 1 and 2.NOTE: You may assume the that other than white-space, the user’s input will be correct. For example, you do not need to check if the hours per week or hourly wage are numbers – you can assume they will be provided correctly. |
Your first name: ABDEL
Your last name: Zhang
Hours you work per week: 30
Hourly wage: 18.88
Employee: ZHANG, Abdel
$2265.60 Monthly salary (gross)
$-566.40 25% Tax deduction
$1699.20 Monthly salary (net)
See accompanying video: http://www.eecs.yorku.ca/~mbrown/EECS1015midterm.mp4
TASK 2
[Testing: Variables and expression, strings, conditional-statements, loops]
Function task2 allows users to order items from a menu as shown below.
The user starts out with a total $10.00. Your function should begin by printing out the user’s balance (amount of money they have left) and the 4 menu items below with the associated prices (you need to use the exact items and prices below). The user can then input the item they’d like to order. They can enter 0 to exit.
You have $10.00 – what item do you want?
Depending on what input the user provides you should do the following:(1) Make sure they have enough money to purchase the item.(2) If they do, print out “Order for *ITEM* confirmed.” (replace ITEM with what they purchased).(3) Deduct the item’s price from the total. |
1: Falafel $3.00
2: Pizza $6.00
3: Salad $1.50
4: Coffee $1.00 Enter 0 to exit.
Your order: 1
Order for *falafel* confirmed.
You have $7.00 – what item do you want?
1: Falafel $3.00
2: Pizza $6.00
3: Salad $1.50
4: Coffee $1.00 Enter 0 to exit.
Your order: 2
Order for *pizza* confirmed.
(1) User enters a 0 or has no more money.
You have $1.00 – what item do you want?
4: Coffee $1.00 Enter 0 to exit. Your order: 4
(1) WHAT TO DO IF THE USER DOES NOT HAVE ENOUGH MONEY? or (2) puts in a order that isn’t “1” to “4”?
You have $1.00 – what item do you want? (1) If the user does not have enough money for an
1: Falafel $3.00 item, print the following “Sorry, you don’t have
2: Pizza $6.00 enough money for that item”.
3: Salad $1.50
4: Coffee $1.00 (2) If the user inputs an order that is not “1” to “4”, Enter 0 to exit. just repeat and ask what they would like to purchase.
Your order: 1
Sorry, you don’t have enough money for that item.
See accompanying video: http://www.eecs.yorku.ca/~mbrown/EECS1015midterm.mp4
TASK 3
[Testing: Variables and expression, strings, conditional-statements, loops]
Function task3 should perform as follows:
Simulate rolling a dice 10 times. Each roll generates a random number between 1-6 and print it as shown below. If a [6] is rolled, print it out with ** around it (see below). If two or more of the rolls are a “6”s, print “YOU WIN”, otherwise print “YOU LOSE”.
Keep repeating the game until the user types in a “N”. See below:
Rolling dice 10 times . . .
[3]
[1]
[1]
[4]
[3]
[1]
[5]
[2]
[2]
[3]
YOU LOSE!
Do you want to play again? (Y/N):
Rolling dice 10 times . . .
[2]
[2]
*[6]* [1]
*[6]*
[5]
*[6]*
[1]
[5]
[3] YOU WIN!
Do you want to play again? (Y/N): N
See accompanying video: http://www.eecs.yorku.ca/~mbrown/EECS1015midterm.mp4
Task 4
[Testing: Variables and expression, strings, conditional-statements, loops, functions]
Function task4 will require you to also define three additional functions as follows:
- generateDNASequence() -> returns a string a string of 40 characters
- applyGammaRadiation(param: string) -> returns a string of 40 characters 3. detectMutation(param: string1, string2) -> returns a string of 40 characters
See figure below that explains the relationship of the three functions. Further details are provided after the figure.
Task 4 should be implemented as follows:
- Task4 should first call the function generateDNASequence(). The function generateDNASequence() will return a string of 40 The string should be randomly generated character by character. Each character can be only one of the following characters: “T”, “G”, “C”, or “A”. These characters are the letters used to describe a DNA sequence. The function should return the randomly generated string.
See an example string: TCTTGCTGTTACAGGATATGATGCTGCTGCGACGCCAGCC
Task 4’s description continues on the next page . . .
- Task4 should now call the function applyGammaRadiation(param: string)
The function applyGammaRadiation() should be passed the string created by the function generateDNASequence() as an argument as shown in the figure. The function applyGammaRadiation() has a 50% chance to mutate one of the letters in the DNA sequence.
[Compute 50% chance?] To perform the 50% chance mutation, compute a random number between 1 and 100. If the number is greater than 50, mutate the DNA sequence. Otherwise, don’t mutate it.
[How to mutate the sequence?] Randomly select one of the letters in the DNA string (recall the string is size 40 characters). For the letter at your selected position, you should then randomly change its value to one of the other allowed DNA values. For example, say you selected position 30 to mutate and it has the letter “A”. Then you need to randomly select “T”, “G”, or “C”. If at position 30 it instead had the letter “C”, then you would need to randomly change it to “A”, “G”, or “T”.
[What to return?] If you mutated the string, then you should return a new string where one of the DNA letters has been changed.
Here is an example:
TCTTGCTGTTACAGGATATGATGCTGCTGCGACGCCAGCC (parameter passed to function)
TCTTGCTGTTACAGGATATGATGCTGCAGCGACGCCAGCC (return string with a mutation)
If no mutation occurred, then return the same string passed. For example:
TCTTGCTGTTACAGGATATGATGCTGCTGCGACGCCAGCC (parameter passed to function)
TCTTGCTGTTACAGGATATGATGCTGCTGCGACGCCAGCC (return string with no mutation)
(3) Task4 should now call the function detectMutation(string1, string2)
The function detectMutation(string1, string2) is passed the original DNA string and the DNA string after gamma radiation has been applied. Detecting a mutation must be done by comparing each characters in the two DNA string sequences to see if they are the same or different. The function detectMutation should return a new string that is 40 characters long. If there is no mutation, this string will be all spaces, however, if there is a mutation then place a “^” in the string at that location the mutation occurred.
Here is an example (with a mutation):
Parameters: “TCTTGCTGTTACAGGATATGATGCTGCTGCGACGCCAGCC”
“TCTTGCTGTTACAGGATATGATGCTGCAGCGACGCCAGCC” Returns: ” ^ ”
Here is an example (without mutation):
Parameters: | “TCTTGCTGTTACAGGATATGATGCTGCTGCGACGCCAGCC”“TCTTGCTGTTACAGGATATGATGCTGCTGCGACGCCAGCC” |
Returns: | ” “ |
Task 4’s description continues on the next page . . .
Now that you have seen the functions, task4 should print out as follows:
MUTATION DETECTED
Or, when no mutation is present, print out:
Reviews
There are no reviews yet.