--- tags: Python --- # Python Self-Check 3 CS 1358 Introduction to Programming in Python Fall Semester 2022 Prof. Pai H. Chou Self-Check 3 Due Date: -- Answer the following questions to check your understanding of your material. Expect the same kind of questions to show up on your tests. For this course, we use vi and vim interchangeably. ## 1. Definitions and Short Answers 1. When you call the function ord('A') it returns 65. What does it mean? ``` 65 is ASCII code of A ``` 2. What is the value of chr(70)? (based on the knowledge of the previous question) ``` 'F' ``` 3. What is the difference between ASCII character set and Unicode? If a character is in ASCII, is it also in Unicode? Are there characters in Unicode that are not in ASCII? ``` Unicode includes ASCII and extend character ``` 4. How is newline (also known as a line feed) represented as a string literal? In other words, how do you print a newline? ``` print('\n') ``` 5. What is a carriage return? What is its string literal, and what effect does it have when printed? ``` carriage return:move cursor to beginning of this line '/r' move cursor to beginning of this line ``` 6. From the command line, what keys do you type to kill a running Python program? ``` Ctrl-C ``` 7. Give an example of a string literal for McDonald's ``` 'McDonald\'s' ``` 8. Give an example of an integer literal ``` 12 0x12 ``` 9. Give an example of a floating point literal ``` 3.12312 ``` 10. What is the difference between print(hello) and print("hello")? ``` print(hello) is to print the value of variable hello print("hello") only print hello ``` 11. What is a numeral? What is the difference between a numeral and a number? ``` numeral is a notation for numbers number is the numeric quantity ``` 12. What is the value of the integer literal 0b101? Express your answer in base-10 or in English. ``` 5 ``` 13. What is the octal literal for the integer value 10? ``` 12 ``` 14. What is the value of the integer literal 0x12? Express your answer in base-10 or in English. ``` 18 ``` 15. What is the return value of ``` int('20') //20 int('0x20') //32 oct(16) //0o20 bin(16) //0b10000 ``` 16. What is the value of ``` 0b0101 & 0b1100 //4 0b0101 | 0b1100 //13 0b0101 ^ 0b1100 //9 ~0b0011 //-4 0b1011 << 2 //44 0b1011 >> 2 //2 ``` 17. What are two possible values of the bool class? ``` True and False ``` 18. What is the value of ``` True and False //False True or False //True True and True //True True or False //True False and False //False False or False //False ``` 19. What is the value of ``` bool(20) //True bool(0) //False bool(None) //False bool([ ]) //False bool([]) //False bool(0.0) //False bool('0') //True bool('hello') //True bool('zero') //True bool('') //False bool(' ') //True bool("") //False bool('''''') //False bool("""""") //False bool('""') //True bool("''") //True ``` 20. What is the value of ``` **A and B // if A is false return B **A or B // if A is true return A 20 or False //20 20 and False //False False and 20 //False False or 20 //20 [ ] or 20 //20 [ ] and 20 //[] 20 or [ ] //20 20 and [ ] //[] 30 or 20 //30 20 or 30 //20 ``` 21. Assume x = 3 and y = 2, what is the value of ``` x == 3 and y > 2 //False x <= 3 and y >= 2 //True x != 3 or y >= 2 //True x != 3 and y == 2 //False x >= 3 >= y > 2 //**False //(x >= 3 >= y > 2) equals (x >= 3) and (3 >= y) and (y > 2) x >= 3 > y >= 2 //**True //(x >= 3 > y >= 2) equal (x >= 3) and (3 > y) and (y >= 2) not (x != 3) and not (y < 2) //True ``` 22. What is the value of ``` "hello" > "Hello" //True 'hello' > 'world' //False 'hello' == 'HELLO' //False 'hello' == 'he11o' //False '2000' == '2OOO' //False 'Abacus' < 'abacus' //True 'about' < 'abnormal' //False 'I' == '|' //False 'ZOO' != '200' //True 'uber' == 'über' //False 'naive' == 'naïve' //False 'Dijkstra' == 'Dijkstra' //False ``` 23. What is the meaning of lexicographical order? ``` "dictionary order", but case sensitive ``` 24. What is the data type of 2+3j? What is the meaning of 3j? ``` complex number imaginary components ```