Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. 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

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

Step: 3

blur-text-image

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

Advances In Databases 11th British National Conference On Databases Bncod 11 Keele Uk July 7 9 1993 Proceedings Lncs 696

Authors: Michael F. Worboys ,Anna F. Grundy

1993rd Edition

3540569219, 978-3540569213

More Books

Students also viewed these Databases questions

Question

7. What decisions would you make as the city manager?

Answered: 1 week ago

Question

8. How would you explain your decisions to the city council?

Answered: 1 week ago