Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Build a module currency, which includes the following three functions that do currency conversions: to_euro(dollar): This function receives US Dollar as an argument and converts

Build a module currency, which includes the following three functions that do currency conversions:

to_euro(dollar): This function receives US Dollar as an argument and converts it to Euro.1 US Dollar = 0.81 Euro.Return Euro.

to_yen(dollar): This function receives US Dollar as an argument and converts it to Japanese Yen.1 US Dollar = 106.45 Yen.Return Yen.

to_peso(dollar): This function receives US Dollar as an argument and converts it to Mexican Peso.1 US Dollar = 18.58 Peso.Return Peso.

Store these three functions in a file namedcurrency.py.

Make a file for the main module.Name the filelab12P2.py.

Define a main function in the main module to do the following:

(1) Ask the user to choose a foreign currency: Euro, Japanese Yen or Mexican Peso.

Design a loop to validate user input. If an invalid choice is made, display an error message and ask the user to choose a foreign currency again until the choice is valid.

(2) Ask the user to enter US dollar amount. Design a loop to validate user input. If the US dollar amount is negative, display an error message and ask the user to reenter it until it is non-negative.

(3) Call one of the three functions in the currency module to convert US dollar to the foreign currency chosen by the user

(4) Receive and display the converted foreign currency

The following is an example.

Converting US Dollar to a foreign currency.

Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: 4

Error: Invalid Choice

Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: 5

Error: Invalid Choice

Enter 1 for Euro, 2 for Japanese Yen, 3 for Mexican Peso: 2

Enter US Dollar: -100

Error: US Dollar cannot be negative.

Enter US Dollar: -200

Error: US Dollar cannot be negative.

Enter US Dollar: 100

It is converted to 10645.0 Yen

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

1. What is the core product that Revlou sells?

Answered: 1 week ago