capstone: retrieving, processing, and visualizing data with python coursera answers

Python for Everybody - A Review

1. What is the most common Unicode encoding when moving data between systems?

  • UTF-32
  • UTF-128
  • UTF-16
  • UTF-8
  • UTF-64

2. What is the decimal (Base-10) numeric value for the upper case letter "G" in the ASCII character set?

  • 71
  • 7
  • 2048
  • 17
  • 1771

3. What word does the following sequence of numbers represent in ASCII: 108, 105, 115, 116

  • open
  • fuss
  • lost
  • http
  • list

4. How are strings stored internally in Python 3?

  • EBCDIC
  • UTF-16
  • Latin
  • Unicode
  • ASCII

5. When reading data across the network (i.e. from a URL) in Python 3, what method must be used to convert it to the internal format used by strings?

  • decode()
  • convert()
  • msub()
  • encode()
  • more()

6. Which of the following lines will never print out regardless of the value of "x"?

if x < 2 :
print(“Below 2”)
elif x < 0 :
print(“Negative”)
else :
print(“Something else”)
  • Negative
  • Something else
  • All the lines will print out
  • Below 2

7. Which of the following lines will never print out regardless of the value for x?

if x < 2 :
print(“Below 2”)
elif x < 20 :
print(“Below 20”)
elif x < 10 :
print(“Below 10”)
else :
print(“Something else”)
  • Below 10
  • Below 20
  • Something else
  • Below 2

8. What would the following Python code sequence print out?

zap = “hello there bob”
print(zap[4])
  • hello
  • zap
  • You would get an out-of-range error and the program would fail
  • e
  • o
  • l

9. Which of the following lines of Python code contains a syntax error?

x = 12
if x < 5:
print(“smaller”)
else:
print(“bigger”)
print(“all done”)

10. What will the following Python program print out?

def fred():
print(“Zap”)

def jane():
print(“ABC”)

jane()
fred()
jane()
  • Zap ABC Zap
  • Zap Zap Zap
  • ABC Zap jane
  • Zap ABC jane fred jane
  • ABC Zap ABC

11. Where in the computer is a variable such as "X" stored?

x = 123
  • Output Devices
  • Main Memory
  • Central processing unit
  • Secondary Memory
  • Input Devices

12. What is the primary use of the Python dictionary?

  • To look up all of the methods which are available on a Python object
  • To make sure that the definitions of the Python reserved words are available in different languages (French, Spanish, etc)
  • To store key / value pairs
  • To insure that all Python reserved words are properly spelled

13. What does the following Python code print out?

stuff = [‘joseph’, ‘sally’, ‘walter’, ‘tim’]
print(stuff[2])
  • walter
  • tim
  • joseph
  • sally

14. What will the following Python program print out? (This is a bit tricky so look carefully).

def hello():
print(“Hello”)
print(“There”)

x = 10
x = x + 1
  • Hello There 11
  • 11
  • Nothing will print
  • x = 11

15. What will the following Python program print out?

x = -1
for value in [3, 41, 12, 9, 74, 15] :
if value > x :
x = value
print(x)
  • 74
  • -1
  • 9
  • 3
  • 15

16. What will the following Python program print out?

total = 0
for abc in range(5):
total = total + abc
print(total)
  • 5
  • 16
  • 10
  • 4
  • 6

17. The following Python code causes a traceback:

a = “123”
b = 456
c = a + b
print(c)

Which line fails with a traceback?

  • 3
  • 1
  • 2
  • 4

18. In the following example, an error occurs in "line3" that normally causes a traceback if it were not in a try/except.

line1
try:
line2
line3
line4
except:
line5
line6

What is the sequence of lines executed in this program?

  • line1, line2, line3, line5, line6
  • line1, line5, line6
  • line1, line4, line5, line6
  • line1, line2, line3, line4, line5, line6
  • line1, line2, line3, line6

19. What would the following Python code print out?

abc = “With three words”
stuff = abc.split()
print(stuff)
  • [‘w’, ‘i’, ‘t’, ‘h’]
  • [‘With three words’]
  • [‘With’, ‘three’, ‘words’]
  • [‘With the’, ‘ee words’]
  • [‘With’, ‘three words’]

20. What would the following Python code print out?

abc = “With three words”
stuff = abc.split()
print(len(stuff))
  • 2
  • 14
  • 3
  • 1
  • 16

21. Which of the following is not a good synonym for "class" in Python?

  • template
  • pattern
  • blueprint
  • direction

22. What is "self" typically used in a Python method within a class?

  • To set the residual value in an expression where the method is used
  • The number of parameters to the method
  • To refer to the instance in which the method is being called
  • To terminate a loop

23. How is a Python socket different than a Python file handle?

  • The socket does not read all of the data when it is opened
  • You can read and write using the same socket
  • Opening a socket will never fail, while opening a file can fail

24. In the following XML, what is "type"?

<person>
<name>Chuck</name>
<phonetype=”intl”>
+1 734 303 4456
</phone>
<emailhide=”yes”/>
</person>
  • XML syntax error
  • Tag
  • Simple element
  • Complex element
  • Value
  • An attribute

25. Which programming language serves as the basis for the JSON syntax?

  • JavaScript
  • PHP
  • Python
  • SCALA
  • Java

Leave a Reply