How to automate boring stuff with python chapter 2: Practice Questions

Practice Questions 
1.  What are the two values of the Boolean data type? How do you write  them? 
2.  What are the three Boolean operators? 
3.  Write out the truth tables of each Boolean operator (that is, every possible combination of Boolean values for the operator and what they  evaluate  to). 
4.  What do the following expressions evaluate to? 
5.  What are the six comparison operators? 
6.  What is the difference between the equal to operator and the assignment  operator? 
7. Explain what a condition is and where you would use one. 
8.  Identify the three blocks in this code:
9.  Write code that prints  Hello  if  1  is stored in  spam, prints  Howdy  if  2  is stored in  spam, and prints  Greetings!  if anything else is stored in  spam. 
10.  What can you press if your program is stuck in an infinite loop? 
11.  What is the difference between  break  and  continue? 
12.  What is the difference between  range(10),  range(0, 10), and  range(0, 10, 1) in a  for  loop? 13.  Write a short program that prints the numbers  1  to  10  using a  for  loop. Then write an equivalent program that prints the numbers  1  to  10  using a  while  loop. 
14.  If you had a function named  bacon()  inside a module named  spam, how would you call it after importing  spam? 

Extra credit:  Look up the  round()  and  abs()  functions on the Internet, and find out what they do. Experiment with them in the interactive shell.

Comments

Popular posts from this blog

Python FAQs

File Permission Systems in Computer