Coursera Programming for Everybody-Getting Started with Python-Week 5 Chapter 3- quiz answers


These solutions are for reference only.

It is recommended that you should solve the assignment and quiz by yourself honestly then only it makes sense to complete the course.

but if you cant figure out some part of it than you can refer these solutions

make sure you understand the solution  

dont just copy paste it


1  What do we do to a Python statement that is immediately after an if statement to indicate that the statement is to be executed only when the if statement is true?

ans  Indent the line below the if statement

2  Which of these operators is not a comparison / logical operator?


3  What is true about the following code segment: if x == 5 : print ‘Is 5’ print ‘Is Still 5’ print ‘Third 5’

ans  Depending on the value of x, either all three of the print statements will execute or none of the statements will execute

4  When you have multiple lines in an if block, how do you indicate the end of the if block?

ans  You de-indent the next line past the if block to the same level of indent as the original if statement

5  You look at the following text: if x == 6 : print ‘Is 6’ print ‘Is Still 6’ print ‘Third 6’. It looks perfect but Python is giving you an ‘Indentation Error’ on the second print statement. What is the most likely reason?

ans  You have mixed tabs and spaces in the file

6  What is the Python reserved word that we use in two-way if tests to indicate the block of code that is to be executed if the logical test is false?

ans  else

7  What will the following code print out? x = 0 if x < 2 : print ‘Small’ elif x < 10 : print ‘Medium’ else : print ‘LARGE’ print ‘All done’

ans Small All done

8  For the following code, if x < 2: print ‘Below 2’ elif x >= 2: print ‘Two or more’ else: print ‘Something else’. What value of ‘x’ will cause ‘Something else’ to print out?

ans This code will never print ‘Something else’ regardless of the value for ‘x’

9  In the following code (numbers added) – which will be the last line to execute successfully? (1) astr = ‘Hello Bob’; (2) istr = int(astr); (3) print ‘First’, istr; (4) astr = ‘123’; (5) istr = int(astr); (6) print ‘Second’, istr

ans  1

10  For the following code: astr = ‘Hello Bob’ istr = 0 try: istr = int(astr) except: istr = -1. What will the value be for istr after this code executes?

ans   -1