The_Ideas

profileKhaled133
ola4s16.pdf

CSCI 1170 Open Lab Assignment #4

Program due: Wednesday, March 23

Problem Description: You will be revising the OLA 3 using functions. Write a currency conversion program

that displays a menu and processes the user’s choices as shown in the sample runs using Python. Your

program should meet the requirements specified below.

Program details and requirements: (same as ola3)

1) Print the purpose of the program. (Currency converter)

2) Use 1$=0.91Euro, $1 = 1.37CAD, $1 = 0.72pound, and $1 = 6.53Yuan for exchange rates.

3) Display a menu and process the user’s choices as shown a sample run below.

4) If the user fails to enter a valid choice, the program must output an error message (as shown in the sample

run) and then repeat the request until the user enters a valid choice. (Use a while loop.)

5) Your program must process the user’s choices until the user wants to quit. (the same while loop.)

6) Use a multi-way if (elif) statement in processing the option.

7) The while statements and multi-way if statements should NOT contain redundant logical expressions.

8) The program must have a beginning comment block and proper documentation as shown in the class

notes for OLA #1.

Program details and requirements: (Revision for ola4)

1) Design print_menu function that prints the menu. This function is a void with no argument function.

2) Design currency_convert function that has two arguments: exchange rate and name of the currency unit

such as "euro" or "yuan". This can be a void function that takes an exchange rate and the currency unit to

calculate and print the result.

3) Once the currency unit is selected, your program should ask whether to convert from or to USD as shown

in the examples. This should be using a while loop to get a correct response.

Sample Program Execution:

The purpose of program:(not shown here)

Please choose from the menu.

============================

1: Convert between USD and EUR

2: Convert between USD and Canada

3: Convert between USD and UK (GBP)

4: Convert between USD and China

5: Quit.

============================

Enter your choice: 7

7 is an invalid choice.

Please choose from the menu.

============================

1: Convert between USD and EUR

2: Convert between USD and Canada

3: Convert between USD and UK (GBP)

4: Convert between USD and China

5: Quit.

============================

Enter your choice: 1

Would you like to convert (1)from or (2)to USD? 2

Enter the amount in euro: 100

100euro is $109.89

Please choose from the menu.

============================

1: Convert between USD and EUR

2: Convert between USD and Canada

3: Convert between USD and UK (GBP)

4: Convert between USD and China

============================

Enter your choice: 2

Would you like to convert (1)from or (2)to USD? 1

Enter the amount in dollar: 100

$100 is 137.00cad

Please choose from the menu.

============================

1: Convert between USD and EUR

2: Convert between USD and Canada

3: Convert between USD and UK (GBP)

4: Convert between USD and China

============================

Enter your choice: 2

Would you like to convert (1)from or (2)to USD? 2

Enter the amount in cad: 100

100cad is $72.99

Please choose from the menu.

============================

1: Convert between USD and EUR

2: Convert between USD and Canada

3: Convert between USD and UK (GBP)

4: Convert between USD and China

============================

Enter your choice: 3

Would you like to convert (1)from or (2)to USD? 5

5 is an invalid option.

You need to enter either 1 or 2.

Would you like to convert (1)from or (2)to USD? 4

4 is an invalid option.

You need to enter either 1 or 2.

Would you like to convert (1)from or (2)to USD? 1

Enter the amount in dollar: 200

$200 is 144.00pound

Please choose from the menu.

============================

1: Convert between USD and EUR

2: Convert between USD and Canada

3: Convert between USD and UK (GBP)

4: Convert between USD and China

============================

Enter your choice: 5

Thank you for using my program.

PROGRAM:

1. login to ranger 2. cd OLA (Your OLAs must be stored in the directory OLA in your class account.) 3. idle3 & (Open a new file and type the program and save as ola4.py in OLA.) 4. Run your program in python shell by click on <F5> key

SUBMISSION:

1. Electronic submission

Submit your assignment using the following UNIX command on ranger.

To submit your source code (program)

turnin c1002300 ola4 ola4.py (for section 2)

turnin c1645300 ola4 ola4.py (for section 5)

Ony one late turn in is allowed for a semester

turnin c1002300 lateola ola4.py (for section 2)

turnin c1645300 lateola ola4.py (for section 5)

If there is a problem with submission, email your file (subject: Problem with Submission of OLA4) immediately

to [email protected]

2. Hard copy submission

 Attach a printed (hard copy) of your script file (YourLastName4.log) that includes run of your program using the following commands.

$ script YourLastName4.log

$ cat -n ola4.py

$ python3 ola4.py #run with the above data set

$ exit

Printed copy of the script file as described above (YourLastName4.log).

ranger $ lph YourLastName4.log

Hard copy submission: Circle all Unix commands. Turn in the printed copy of the script file

(YourLastName4.log) described above and the completed evaluation form (next page) in a folder with your name,

section number, and your account id.

OPEN LAB 4 EVALUATION FORM

Due: 3/23/2014

Account No:________________ section ______ Name: ________________________

 Grade your program and turn in this evaluation form.

specification Solve the assigned problem using methods described in program description.

documentation Main Comment Block (file name (1), due date (1), author(1), course #(1)

description(1), input/output(1)). __/6

documentation Each variable documented. (purpose of the variable should be documented) __/2

documentation Each function and section of statements in the program well documented. __/5

Style Use indentation to make the program easier to read. __/3

Style Use white spaces in appropriate places for readability. __/3

Style Meaningful names for variables. __/3

specification

Print the purpose and ending of the program. __/3

None of the Draw functions have input statement -10

 The program output meets the problem specification.

 print_menu function that is a void with no argument function.

 currency_convert function that has two arguments: exchange rate and name of the currency unit such as "euro" or "yuan".

 Once the currency unit is selected, ask whether to convert from or to USD as shown in the examples. Use a while loop to get a correct response.

 Print the purpose of the program.

 Display a menu and process the user’s choices as shown a sample run above.

 If the user fails to enter a valid choice, the program must output an error message (Use a while loop.)

 Your program must process the user’s choices until the user wants to quit.

 Use a multi-way if (elif) statement in processing the option.

__/50

Execution Compile without errors.

Execution Execute without crashing. __/5

Execution Work for all data and produce correct answers. __/5

Output The program output well formatted. (spacing, indentation etc.) __/3

Output The program output properly labeled and identified. __/3

The script file contains program listing using “cat –n ola4.py” command __/2

The script file contains a run of program using “python3 ola4.py” command __/10

Your name is on all material. -2

Hand in this evaluation form with grade. __/2

Hard copy submission. -10

TOTAL __/100 %

Time log Time spent on reading/understanding the problem specification ___/min

2pts Time spent on developing an algorithm ___/min

Time spent on coding ___/min

Time spent on testing/debugging ___/min