Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


CS0011 Introduction to Computing for Scientists Project 1 - Lab 3

Lab3

Input validation

In this part of the lab you will implement input treatment on the menu selection of your program.

When your program asks the user for their preferred output format (human-readable or CSV) if the user does not enter a valid choice, they should be continually prompted until a valid choice is entered.  (use a loop to accomplish that)

Sample output

How would you like to format the output?

1: CSV

2: Human-readable

Enter 1 or 2: 5

Invalid choice! Please try again

Enter 1 or 2: -2

Invalid choice! Please try again

Enter 1 or 2: no

Invalid choice! Please try again

Enter 1 or 2: 1

Fuel,Velocity,Duration,Fuel cost,Losses,Value lost                                      10000,953.1017980432493,910.768983268842,10000000,109292277.99226104,119292277.99226104

Adding a maximum of number of tries for your menu

Sometimes, it is desirable to add a maximum number oftimes a user can try to select an option and if after that number of attempts is exceeded the program should provide some feedback and do something other than to keep asking the user for that information. Modify your menu to keep track of incorrect attempts. In case the user has entered an invalid option for  5 times in a row your program should print “Too many incorrect attempts. Exiting program” and finish execution. To stop  executing, you can call the exit() function. You can customize a message to be displayed by passing a string as argument to exit() i.e. exit(‘your message here’) or just add an extra condition (attempts < max_attempts) to be checked in your loop.

Sample output

How would you like to format the output?

1: CSV

2: Human-readable

Enter 1 or 2: 5

Invalid choice! Please try again

Enter 1 or 2: -2

Invalid Enter 1 Invalid Enter 1 Invalid Enter 1

choice! or 2: 9 choice! or 2: 6 choice! or 2: 8

SystemExit: Too


Please try again

Please try again

 

Please try again

 

many incorrect attempts! Exiting program.


Rubric

Your program will be evaluated according to the following rubric:

input validation for desired output format

25

tried many amounts of fuel

10

prints header correctly

15

prints CSV correctly

25

prints human-readable correctly

25