Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following short Python program bas THREE syntax errors and Two nun-time erro

ID: 3865120 • Letter: T

Question

The following short Python program bas THREE syntax errors and Two nun-time errors. Identify these five errors by circling the line which has the error and briefly describe (in the white box to the right) what the error is and how to fix it: item = input(' Enter item name:')) if item = =''; print ('Error: item has no name ') elif len (item) rightarrow 20: print ('Error: item name is too long') price input ('Enter item price:') discountRate 1 = 0.03 discountRate2 = 0.04 if price threshold; if input List[i] > threshold; print(inputlist[counter]) counter = counter +1

Explanation / Answer


Answer for question1:


The syntax errors are in the lines mentioned below:

1) item = input('Enter item name: ')) -----> one extra closing brace ')'. It has to be like this : item = input('Enter item name: ')


2) elif len(item) => 20: -------> The syntax to check greater than and equal to is '>=' and not '=>'. It has to be like this : elif len(item) >=20


3) elif price = 100: -------> The syntax to check equality is '==' and not '='. It has to be like this : elif price == 100

4) else ----> There is a missing semicolon at the end of the statement. It has to be like this : else:

Runtime errors:

1) input evaluates the input and returns the result of evaluation. However raw_input doesn't evaluate the data and returns the string as is.

Answer for question2:

The following errors are notices:

1) In the given function 'i' is not defined

2) In the while loop is inputList is trying to print the out of range list values if 'i' is defined as 0

To test this function try to put this statement 'print printItems([1,2,"df",5])' at the end of the program for testing. Also declare i = 0