Input and Output Debugging#

Section Title: IO Debugging

  • Each of the following short code contains one or more bugs.     

  • Please identify and correct these bugs.

  • Provide an explanation for your answer.

Question-1#

print 'Hello'

Solution

Parentheses are missing.

Question-2#

print('Hello)

Solution

Single quote on the right of Hello is missing.

Question-3#

print('Hello'))

Solution

There is an extra paranthesis at the end.

Question-4#

print = 3
print('England')

Solution

  • In the first line print becomes a variable and it’s value is 3.

  • In the second line print is tried to used as a function but it is not a function anymore.

Question-5#

x = input(Enter your birthyear:)
print(x)

Solution

Single quotes of the string inside the input function are missing.

Question-6#

x = input('Enter your birthyear: ')
print('Your age is', 2022-x)

Solution

Type of x is string so subtraction cannot be done.

Question-7#

print('A',2,3,'B', separator='++')

Solution

The name of the parameter is sep (not separator).

Question-8#

first name = input('Enter your first name: ')
print(first name)

Solution

Variable names (first name) cannot have a space.

Question-9#

print('A','B', 'C', sep=9)

Solution

The sep parameter value (9) must be a string (‘9’).