Question
. Please write the following code in Python 3. Also, please show all outputs. THE FIRST PART OF THE PROGRAM IS WRITTEN BELOW PLEASE WRITE
. Please write the following code in Python 3. Also, please show all outputs.
THE FIRST PART OF THE PROGRAM IS WRITTEN BELOW PLEASE WRITE THE SECOND PART?
Error Handling
Coding assignments can be saved as .py files when appropriate or .txt files otherwise, for example, you may want to past the code from multiple .py files into a single .txt file. When you've completed the assignment, attach the file(s) to the drop box for this module, which you'll find near the end of the module. Please be sure to include your last name and the course number in the file name of the document, like so: "your name X442.3 Assignment 7."
Suppose you want to determine whether an arbitrary text string can be converted to a number. Write a function that uses a try/except clause to solve this problem. Can you think of another way to solve this problem?
The input function will read a single line of text from the terminal. If you wanted to read several lines of text, you could embed this function inside a while loop and terminate the loop when the user of the program presses the interrupt key (Ctrl-C under UNIX, Linux and Windows.) Write such a program, and note its behavior when it receives the interrupt signal. Use a try/except clause to make the program behave more gracefully.
PROGRAM PART ONE
##########################################################################
def convertStr2Int(): string = input('Enter string to be checked:') try: number = int(string) print('String {:s} is converted to number {:d}'.format(string, number)) except ValueError: print("{:s} cannot be converted to a number.".format(string)) ##########################################################################################################
PLEASE WRITE SECOND PART AND SHOW OUTPUT
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