Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PYTHON ASSIGNMENT: Objective Demonstrate an understanding of: Variable Scope Globals f-strings for loops Use of in Specification Start with your code from assignment four. At
PYTHON ASSIGNMENT:
Objective Demonstrate an understanding of: Variable Scope Globals f-strings for loops Use of "in" Specification Start with your code from assignment four. At the module level, create a global variable called home_currency and set it to the empty string. Create a function called currency_options() with a string parameter base_curr. The function should print out a table of options for converting base_curr to all other currencies. Use quantities of the base currency from 10 to 90 and use the currency_converter() function to calculate all of the other currency values. Be sure to look at the sample run below for an example. Note that you must use f-strings to generate the lines of the table, Use a for loop to print the header line. Do not hard code the header. Hint: If you have typed 'EUR' anywhere in your currency_options function, you have hard-coding. You must use a for loop instead of writing a separate line of code for each of the nine lines. Do not hard code the lines. Hint again: If you have typed 'EUR' anywhere in your currency_options function, you have hard-coding. Do not use the home_currency global anywhere in the currency_options() function. home_currency should not appear anywhere in this function, use base_curr instead. The base_curr must appear as the first column, and should not be duplicated in the table. This will require use of a nested for loop, and the continue keyword might come in handy here. The columns of the table must be evenly spaced. You can choose to left-justify or right-justify the columns, but they must line up. All currency values should have two decimals of precision throughout the table (25.50 not 25.5 or 26). Inside the main() function, before the menu is called, ask the user for their home currency. Do this in a loop until the user enters a valid string that is one of the entries in the conversions dictionary. Assign the user response to the home_currency global (be careful not to shadow the original home_currency name) Finally, modify the menu() function so that the currency table is printed before entering the loop that manages the menu. To be clear: currency_options() should be called from menu(), not from main(). The currency table should be printed just once during a run of the program. No need for a unit test for this one, but you should include sample code that demonstrates the user entering a bad currency string and then a good one, as well as the printing of the table before the menu. Sample Run (your output can be different as long as it meets the criteria above) Please enter your name: Eric Hi Eric, welcome to Foothill's database project. What is your home currency?MON What is your home currency? GBP Options for converting from GBP: GBP USD EUR CAD CHF 10.00 12.50 11.25 17.50 11.88 20.00 25.00 22.50 35.00 23.75 30.00 37.50 33.75 52.50 35.62 40.00 50.00 45.00 70.00 47.50 50.00 62.50 56.25 87.50 59.38 60.00 75.00 67.50 105.00 71.25 70.00 87.50 78.75 122.50 83.12 80.00 100.00 90.00 140.00 95.00 90.00 112.50 101.25 157.50 106.88 NZD 20.75 41.50 62.25 83.00 103.75 124.50 145.25 166.00 186.75 AUD 20.25 40.50 60.75 81.00 101.25 121.50 141.75 162.00 182.25 JPY 1349.00 2698.00 4047.00 5396.00 6745.00 8094.00 9443.00 10792.00 12141.00 Objective Demonstrate an understanding of: Variable Scope Globals f-strings for loops Use of "in" Specification Start with your code from assignment four. At the module level, create a global variable called home_currency and set it to the empty string. Create a function called currency_options() with a string parameter base_curr. The function should print out a table of options for converting base_curr to all other currencies. Use quantities of the base currency from 10 to 90 and use the currency_converter() function to calculate all of the other currency values. Be sure to look at the sample run below for an example. Note that you must use f-strings to generate the lines of the table, Use a for loop to print the header line. Do not hard code the header. Hint: If you have typed 'EUR' anywhere in your currency_options function, you have hard-coding. You must use a for loop instead of writing a separate line of code for each of the nine lines. Do not hard code the lines. Hint again: If you have typed 'EUR' anywhere in your currency_options function, you have hard-coding. Do not use the home_currency global anywhere in the currency_options() function. home_currency should not appear anywhere in this function, use base_curr instead. The base_curr must appear as the first column, and should not be duplicated in the table. This will require use of a nested for loop, and the continue keyword might come in handy here. The columns of the table must be evenly spaced. You can choose to left-justify or right-justify the columns, but they must line up. All currency values should have two decimals of precision throughout the table (25.50 not 25.5 or 26). Inside the main() function, before the menu is called, ask the user for their home currency. Do this in a loop until the user enters a valid string that is one of the entries in the conversions dictionary. Assign the user response to the home_currency global (be careful not to shadow the original home_currency name) Finally, modify the menu() function so that the currency table is printed before entering the loop that manages the menu. To be clear: currency_options() should be called from menu(), not from main(). The currency table should be printed just once during a run of the program. No need for a unit test for this one, but you should include sample code that demonstrates the user entering a bad currency string and then a good one, as well as the printing of the table before the menu. Sample Run (your output can be different as long as it meets the criteria above) Please enter your name: Eric Hi Eric, welcome to Foothill's database project. What is your home currency?MON What is your home currency? GBP Options for converting from GBP: GBP USD EUR CAD CHF 10.00 12.50 11.25 17.50 11.88 20.00 25.00 22.50 35.00 23.75 30.00 37.50 33.75 52.50 35.62 40.00 50.00 45.00 70.00 47.50 50.00 62.50 56.25 87.50 59.38 60.00 75.00 67.50 105.00 71.25 70.00 87.50 78.75 122.50 83.12 80.00 100.00 90.00 140.00 95.00 90.00 112.50 101.25 157.50 106.88 NZD 20.75 41.50 62.25 83.00 103.75 124.50 145.25 166.00 186.75 AUD 20.25 40.50 60.75 81.00 101.25 121.50 141.75 162.00 182.25 JPY 1349.00 2698.00 4047.00 5396.00 6745.00 8094.00 9443.00 10792.00 12141.00Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started