Answered step by step
Verified Expert Solution
Question
1 Approved Answer
WE AutoSave @ Off H Hands-on 10 - User Validation & Exceptions - Protected View . Saved to this PC v Search Tram Phan TP
WE AutoSave @ Off H Hands-on 10 - User Validation & Exceptions - Protected View . Saved to this PC v Search Tram Phan TP X File Home Insert Draw Design Layout References Mailings Review View Help Comments Viewing Share PROTECTED VIEW This file has been verified by Microsoft Defender Advanced Threat Protection and it hasn't detected any threats. If you need to edit this file, click enable editing. Enable Editing X Hands-On 10- User Validation & Exception Handling 1 - First, let's review exception handling. Review the following output from our program and answer the questions below: Traceback (most recent call last) : File "C:/Users/peter/PycharmProjects/itp150-9/sandbox 99.py", line 44, in score = int (input ('Enter a score: ') ) ValueError: invalid literal for int () with base 10: 'abc' Process finished with exit code 1 A - What is the name of the module that ran? B - What was the line of code in which the exception was raised? C-What are the contents of this line? D - What is the error message that explains the problem? E -What did the user actually type in that is the incorrect value? F-When it states "Process finished with exit code 1", what does the "1" indicate? G - For program that have the output "exit code 0", what does that mean? 2 - Write some code that includes validation of what the user typed in. In this case, the data type expected is a string. Page 1 of 2 542 words Text Predictions: On [D Focus + 100% 42 F 1:33 AM [x O Mostly cloudy w A ENG 3/7/2023WE AutoSave @ Off H Hands-on 10 - User Validation & Exceptions - Protected View . Saved to this PC v Search Tram Phan TP X File Home Insert Draw Design Layout References Mailings Review View Help Comments Viewing Share PROTECTED VIEW This file has been verified by Microsoft Defender Advanced Threat Protection and it hasn't detected any threats. If you need to edit this file, click enable editing. Enable Editing X 2 - Write some code that includes validation of what the user typed in. In this case, the data type expected is a string. Write the code that asks the user for their letter grade. If the letter grade is A, B, or C, print "You passed". If the letter grade is D or F, print "Take the class again". Print an error message if they have entered an invalid letter. Note that for this example, the expected input is a string. The input() function will always return a string. Therefore, we do not need to convert the string input to another data type. This also means that there is no need to check for an exception being raised during data conversion. Therefore: there is no need to add exception handling code. To do proper user validation, we should force the user to enter the data again. Therefore, change this code to include a loop, so that if the user incorrect letter, the program will ask for the letter grade again. Also, because we are dealing with letters, change your code to handle both upper case and lower case letters. This can be done by simply calling the upper() or lower() string method to convert the letters entered by the user. Page 1 of 2 542 words Text Predictions: On [ Focus + 100% 42 F 1:33 AM Mostly cloudy w A ENG 3/7/2023WE AutoSave @ Off H Hands-on 10 - User Validation & Exceptions - Protected View . Saved to this PC v Search Tram Phan TP X File Home Insert Draw Design Layout References Mailings Review View Help Comments Viewing Share PROTECTED VIEW This file has been verified by Microsoft Defender Advanced Threat Protection and it hasn't detected any threats. If you need to edit this file, click enable editing. Enable Editing X 3 - Write some code that includes validation of what the user typed in. In this case, the data type expected is an int. You can add the code to the program from question 2 or do two separate programs/outputs. Write the code that asks the user for an integer score. If the score is greater than 90, print "Great job". Otherwise, print "Study more". Change this code to handle the scenario that the user enters something that is not valid for integer, such as "abc", or 3.9. Note that for this example, the expected input is an int. The input() function will always return a string. Therefore, we need to convert from str to int, and doing so may raise an exception if user has entered non-int data. Therefore: we must do exception handling. What is the exception that will be raised in this case? We must catch that specific exception type. To do proper user validation, we should force the user to enter the data again. Therefore, change this code to include a loop, so that if the user incorrect int, the program will ask for the integer score again. Upload this word document with question 1 answers. Also, upload your py file(s) and output file(s). Remember you can combine but questions 2 and 3 into one py file or do two sets of programs outputs. Page 2 of 2 542 words Text Predictions: On [D Focus + 100% 42 F 1:34 AM Mostly cloudy w A ENG [x O 3/7/2023
WE AutoSave Off H Hands-on 10 - User Validation & Exceptions - Protected View Saved to this PC Layout References Mailings Review View Help File Home Insert Draw Design PROTECTED VIEW This file has been verified by Microsoft Defender Advanced Threat Protection and it hasn't detected any threats. If you need to edit this file, click enable editing. Page 1 of 2 542 words Text Predictions: On 42F Mostly cloudy Search Hands-On 10 - User Validation & Exception Handling 1 - First, let's review exception handling. Review the following output from our program and answer the questions below: Traceback (most recent call last): File "C:/Users/peter/PycharmProjects/itp150-9/sandbox 99.py", line 44, in score int (input ('Enter a score: ')) ValueError: invalid literal for int () with base 10: 'abc' Process finished with exit code 1 A - What is the name of the module that ran? B- What was the line of code in which the exception was raised? C-What are the contents of this line? D-What is the error message that explains the problem? E-What did the user actually type in that is the incorrect value? F - When it states "Process finished with exit code 1", what does the "1" indicate? G-For program that have the output "exit code 0", what does that mean? 2 - Write some code that includes validation of what the user typed in. In this case, the data type expected is a string. Tram Phan TP Fo Focus Enable Editing Comments Viewing 80 ENG 4x O Share X + 100% 1:33 AM 3/7/2023 20
Step 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