Difference between revisions of "CSC111 Homework 3 2015"
(→Problem 7: Formatted output) |
|||
Line 62: | Line 62: | ||
<br /> | <br /> | ||
Submit your program, called hw3.py, to the Moodle HW 3 PB 4 section. | Submit your program, called hw3.py, to the Moodle HW 3 PB 4 section. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<br /> | <br /> | ||
− | =Problem | + | =Problem 5 Teller Machine with pennies.= |
<br /> | <br /> | ||
This time the program accepts inputs of the form 123.55 and will output the change expressed in $20, $10, $5, and $1-bills, along with a number of quaters, dimes, nickels, and cents. | This time the program accepts inputs of the form 123.55 and will output the change expressed in $20, $10, $5, and $1-bills, along with a number of quaters, dimes, nickels, and cents. | ||
<br /> | <br /> | ||
− | Submit your new version of hw3.py to the Moodle HW 3 PB | + | Submit your new version of hw3.py to the Moodle HW 3 PB 5 section. |
<br /> | <br /> | ||
Here is an example of an interaction with the user, who enters 124.46 as the amount to withdraw. | Here is an example of an interaction with the user, who enters 124.46 as the amount to withdraw. | ||
Line 90: | Line 84: | ||
1 cent(s) | 1 cent(s) | ||
− | =Problem | + | =Problem 6: Formatted output= |
<br /> | <br /> | ||
Use your solution for Problem 3, and make it output the result in a box, nicely formatted, as illustrated below. The Moodle test program will be checking with random positive amounts, and your output must match exactly the output below. The user input is 234. | Use your solution for Problem 3, and make it output the result in a box, nicely formatted, as illustrated below. The Moodle test program will be checking with random positive amounts, and your output must match exactly the output below. The user input is 234. | ||
Line 105: | Line 99: | ||
</source> | </source> | ||
<br /> | <br /> | ||
− | Submit your solution program in Section HW3 PB | + | Submit your solution program in Section HW3 PB 6. |
<br /> | <br /> | ||
<br /> | <br /> |
Revision as of 21:32, 11 February 2015
--D. Thiebaut (talk) 10:42, 9 February 2015 (EST)
Contents
Problem 1: Teller Machine: Version 1
Rewrite the program we saw in class that asks the user for some amount of dollars, and outputs the number of $20, $10, $5 and $1 that needs to be distributed. Call your program hw3.py.
In this version, we assume that the user is well behaved and will enter only valid integer numbers.
Make sure you test your program well, so that it works well with particular dollar values, such as 0, 1, 5, 10, and 20.
Submit your program to the Moodle HW 3 PB 1 section.
Here is an example of how your program should behave. The user enters 139 when prompted for a value:
Please enter amount to withdraw: 139 Withdrawal amount: 139 Please lift your keyboard and find: 6 $20-bill(s) 1 $10-bill(s) 1 $5-bill(s) 4 $1-bill(s)
Problem 2: Teller Machine: User sometimes inputs floats
This version of your program should be robust enough to work well, even when the user enters a number of the form 10.25. In such a case your program will only treat the integer part of the sum entered by the user, and will discard the decimal digits. So 10.25 will be treated as 10.
Call your program hw3.py. You will have to take the string returned by the input() function and one or more functions to transform it (the string) into an integer. You will find the page on built-in functions at https://docs.python.org/3/library/functions.html very useful for figuring out which function to use!
Submit your program to the Moocle HW 3 PB 2 section.
Example of user interaction with the program, where the user enters 139.55:
Please enter amount to withdraw: 139.55 Withdrawal amount: 139 Please lift your keyboard and find: 6 $20-bill(s) 1 $10-bill(s) 1 $5-bill(s) 4 $1-bill(s)
Problem 3: The User sometimes inputs negative numbers
Make your program more robust so that if the user enters a minus sign in front of the number, by mistake, your program will discard it. In other words, if the user enters -30.50, your program will treat this number as 30. If the user enters -10, the program will treat it as 10.
Submit your program hw3.py program to the Moodle HW 3 PB 3 section.
Example of user interaction: this time the user enters -122.99
Please enter amount to withdraw: -122.99 Withdrawal amount: 122 Please lift your keyboard and find: 6 $20-bill(s) 0 $10-bill(s) 0 $5-bill(s) 2 $1-bill(s)
Problem 4: Teller Machine with $50-bills
Your new program, also called hw3.py, will now be able to accept negative numbers or floats as input, and will also include a number of $50-bills.
Submit your program, called hw3.py, to the Moodle HW 3 PB 4 section.
Problem 5 Teller Machine with pennies.
This time the program accepts inputs of the form 123.55 and will output the change expressed in $20, $10, $5, and $1-bills, along with a number of quaters, dimes, nickels, and cents.
Submit your new version of hw3.py to the Moodle HW 3 PB 5 section.
Here is an example of an interaction with the user, who enters 124.46 as the amount to withdraw.
Please enter amount to withdraw: 124.46 Withdrawal amount: 124.46 Please lift your keyboard and find: 6 $20-bill(s) 0 $10-bill(s) 0 $5-bill(s) 4 $1-bill(s) 1 quarter(s) 2 dime(s) 0 nickel(s) 1 cent(s)
Problem 6: Formatted output
Use your solution for Problem 3, and make it output the result in a box, nicely formatted, as illustrated below. The Moodle test program will be checking with random positive amounts, and your output must match exactly the output below. The user input is 234.
Please enter amount to withdraw: 234
+--------------------------------+
| Withdrawal amount: $234 |
| $20-bill(s): 11 |
| $10-bill(s): 1 |
| $5-bill(s): 0 |
| $1-bill(s): 4 |
+--------------------------------+
Submit your solution program in Section HW3 PB 6.