click below
click below
Normal Size Small Size show me how
Python Ch. 1 Review
Review of Python Chapter 1
Question | Answer |
---|---|
1. Which mathematical operator is used to raise a number to a power (exponent) in Python? | ** |
2. What data type is the variable "amount" assigned? amount = 430.87 | A float data type |
3. What data type AND value is the variable "total" assigned? total = int(98.5) | An int data type. Value is 98. |
4. How can you print a string that prints data on multiple lines? | using triple quotes or by using "\n" inside the string. |
5. What will this statement do? print ("I'm ready to read "Harry Potter" ") | Result in a Syntax Error, due to the double quotes inside the literal and the double quotes used to enclose it |
6. What will this statement do? print ('I'm ready to read "Harry Potter" ') | Result in a Syntax Error, due to the single quote (apostrophe) inside the literal and the single quotes used to enclose it |
7. What will this statement do? print( """I'm ready to read "Harry Potter" """) | It will print the string literal with NO errors due to the triple quotes enclosure. |
8. If x=10, which print statement will NOT produce a syntax error? a. print ('I have' x 'pairs of shoes') b. print('I have,' x ', pairs of shoes) c. print ('I have', x, 'pairs of shoes') d. none of the above! | c. print ('I have', x, 'pairs of shoes') (you need to separate the items with commas!) |
9. What character starts a comment in Python? | # |
10. What value and data type will the variable x be assigned? x = 11/2 | 5.5 which is a 'float' (in Python, the / divides full division) |
11. What value and data type will the variable y reference? y = 11//2 | 5 which is an 'int' (in Python, the // does integer division and throws away the decimal part) |
12. What is the result of the following expression in Python? 3+4**2-1 | 18 |
13. What is the output of this statement? print (19 % 5) | 4 (19 divided by 5 is 3 remainder 4) |
14. String literals are encolsed with: a. single quotes '' b. double quotes "" c. parenthesis () d. single or double quotes | d. single or double quotes (as long as you use the same one in the beginning and the end!) |
15. Which one(s) will give an error? a. x1 = 100 b. 1x = 100 c. room# = 209 d. room number = 209 | b, c, and d |
16. What will this print? x = 5 y = 3.5 print (x + y) | 8.5 (float data type) |
17. What will this print? x = 7 y = 2 print (x/y) | 3.5 (float data type) |
18. What will this print? x = "10" y = "5" print (x + y) | "105" (string data type) |
19. Which function allows the user to enter information from the keyboard? | input() |
20. What data type is assigned to x? x = input("please enter a number") | x will be a string! |
21. What is the format (syntax) of the input function? | variable = function (question). Example: name = input("What is your name? ") |
22. What will this print? print( (6-3) * 2 + 7 / 2) | 9.5 |