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

FOR PYTHON: Perform the following to the code below: Describe the error(s), if a

ID: 3836004 • Letter: F

Question

FOR PYTHON:

Perform the following to the code below: Describe the error(s), if any Correct the code. There may be more than one error. Do not change the comments ______ correct code # This code prints: #1 #2 # Sample print for idx in range (2): print idx print 'Sample print' _________ correct code # This code asks user for an integer number # then prints the number plus 1 # numin = raw input ('enter an integer number:') print "Your number + 1 is:", numin + 1 ________ correct code # This code will print ODD if the integer # innum is odd, otherwise it will print EVEN if innum%2 = 0: print 'ODD' else: print 'EVEN'

Explanation / Answer

1)

a) errors :

1.idx value will be started from 0, so it prints 0,1 not 1,2.

2. 'Sample print' should not be inside of loop, it shold be outside of loop

b) Correct code:

for idx in range(1,3): #idx starts from 1

print idx

print 'Sample print' # after end of loop it will print

2)

a) errors:

i.) for numbers input will be read by input(), raw_input() is used for strings

ii.) If we '+' opeator to print numin+1 should convert into string otherwise concat of number and string wil throw an error, but here ',' is used it is correct only

b) Correct Code :

numin = input(" Enter integer")

print "Your number + 1 is :", numin + 1

or can be written as

print "Your number + 1 is :" + str( numin + 1)

3)

error)

1. For comparision need to use '==' not '='

2. Logic is wrong, num%2 = 0 means 'Even' and 1 means 'Odd'

Correct Code)

if innum%2 == 0:

print 'EVEN'

else:

print 'ODD'

print "your number + 1 is :" + str(numin + 1)