Py4e: Chapter 3

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is true about the following code segment: if x == 5 : print('Is 5') print('Is Still 5') print('Third 5')

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

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?

Indent the line below the if statement

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')

Small All done

For the following code, if x < 2 : print('Below 2') elif x >= 2 : print('Two or more') else : print('Something else')

This code will never print 'Something else' regardless of the value for 'x'

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

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

You look at the following text: if x == 6 : print('Is 6') print('Is Still 6') print('Third 6')

You have mixed tabs and spaces in the file (it needs to be three spaces not tab depending on your texteditor, atom will atomatically convert tab to the proper spaces.)

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?

else

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?

-1

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)

1

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

=


Set pelajaran terkait

Microsoft Word Chapter 1-4 Midterm

View Set

Respiratory Emergencies and other EMT Class Notes

View Set

PTEC 203 - Assignment 4 - Chapter 3 Theories of Accident Causation

View Set

C784 MODULE 7.11 Conditional probability

View Set

Adaptive Quizzing/Urinary/Reproductive Systems

View Set