Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab Assignment_6 Question 1: Each of the statements in Questions 1 through 8 generates a Traceback error messages. Determine the error message generated by each

image text in transcribed
image text in transcribed
image text in transcribed
Lab Assignment_6 Question 1: Each of the statements in Questions 1 through 8 generates a Traceback error messages. Determine the error message generated by each statement. 1. x=23 ' print(x.startswith (2)) 2. num =(11, '3') . index (3) 3. letter =( "ha" * '5') [9] 4. s=[s, 'e', 'd']['0'] 5. x={1,2,3}[1] 6. (2,3,1).insert (0) 7. num =eval(x=33) 8. del ['11', '12', '13'][0][0] Question 2: Determine the output displayed by the lines of code. 1. Assume the user enters a letter. try: num = float (input ("Enter a number: ")) print("Your number is", num) except: print("You must enter a number.") 2. Assume that the file Ages.txt is located in the current folder and the first line of the file is Twenty-one . try: infile = open ("Ages.txt", ' r ') \# FileNotFound if fails age = int(infile.readline()) \#ValueError if fails print("Age:", age) except FileNotFoundError: print("File Ages.txt not found.") except ValueError: print("File Ages.txt contains an invalid age.") infile.close () else: infile.close() Question 3: Rewrite the following lines of code without using a try statement. phoneBook = \{"Alice": "123-4567", "Bob": "987-6543" } name = input ("Enter a name: ") try: print (phoneBook [name]) except KeyError: print("Name not found.") Determine the output of the program. 1. def main(): def factorial (n) : if n=1 return 1 else: return n * factorial (n1) print (factorial (5)) main() 2. def main(): def digitsum (n) : total =0 while n : totaltwn=10 n=n/10 print (total) digitsum(12345) 3. def main () : def repeatLastLetter (w) : if len (w)=1 : return w else: return repeatLastLetter (w[1:1)+ repeatLastLetter (w[1:])

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions