PythonExamReview_KEY-EXPLANATIONS_ANSWERS

PythonExamReview_KEY-EXPLANATIONS_ANSWERS - Python exam...

Info icon This preview shows pages 1–21. Sign up to view the full content.

View Full Document Right Arrow Icon
Python exam study guide Key Options in green text are correct answer
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
By convention python scripts are stored as text files with extension? a).py b).p c).python d).pyt Explanation: When you go to IDLE, the default file extension is .py. 2
Image of page 2
Python is considered an ______ language. a.interpreted b.compiled c.interactive d.Composed 3
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Explanation uage, called byte code, and then interpreted by a program called a vi
Image of page 4
At python language interpreter's prompt, consider >>> 3 + 2 if above input is given and enter is hit then output should be ? a.2 b.3 c.3+2 d.32 e.5 f.compiling ..... 5
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Explanation Basic addition. 3+2 = 5
Image of page 6
What is the output: a.num ber is greater b.num ber is less c.num ber is equal to d.no output will be printed 7 1.num ber = 99 2.def check_x(): 3. if False : 4. print ( “num ber is greater" ) 5. elif False : 6. print ( "num ber is less " ) 7. else : 8. print ( "num ber is equalto" ) 9. 10.check_x()
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Explanation check_x() is checking to see if number is 0 or 1. Since the nu
Image of page 8
What is the output: a.exclam ation b.no exclam ation c.X LIX d.doesn't print anything 9 x = 49 if x > = 49: print( “XLIX") elif x != 0: print ( "exclam ation") else: print ( "no exclam ation")
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Explanation atement checks if x is greater than or equal to 49. Since x equals
Image of page 10
What is the output: a.exclam ation b.no exclam ation c.error d.doesn't print anything 11 x = 49 if x != 0: print ( "exclam ation") else: print ( "no exclam ation")
Image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Explanation = 49. Since x does not equal 0, it will print exclamati
Image of page 12
What is the output: a.H ello W orld b.Jello W orld c.Error d.Null Explanation: You cannot assign an array elem ent to a string. You w ould have to split the string and turn it into a string array, and then assign the 0th elem ent to j. 13 > > > greeting = 'Hello W orld' > > > greeting [ 0 ] = ' J'
Image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
What is the output: a.This w ill result in an error b.4 c.3 d.1 e.5 14 x = 1 for i in range ( 2 ): for j in range ( 2 ): x + = 1 print (x)
Image of page 14
Explanation rst iteration, x = x+1, which is 1+1, or 2. It keeps going thr
Image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
What is the output: 0 0 0 1 1 0 1 1 16 for i in range ( 2 ) : for j in range ( 2 ) : print (i ,j) 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2 0 0 1 1 2 2 0 0 0 1 0 2 1 0 1 1 1 2 a. b. c. d. Explanation: For every i that can take the values 0 and 1 there will be a j that can take values of 0 or 1. Therefore, the print statement will be executed 2*2 = 4 times.
Image of page 16
What is the output: a) 6 b) 9 c) 8 d) 5 Explanation: The ** denotes an exponential calculation on operators. So 3**4 means 3 to the 4th power (or 3^4). C = 3**2 evaluates to 3^2, which is 9. 17
Image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
What is the output: a) 7 b)'c' Explanation: c = 4*3, so c = 12. c += 1 -> 12+1 = 13 c) 12 d) 13 e) 1 f) There is a syntax error g) There is a runtime error 11
Image of page 18
What is the output: a) 7 b) ‘c’ c) 2 Explanation: 7/3 = 2, with remainder 1. The modulus operator (%) deals with remainders, so 7 % 3 is 1. d) 3 e) 1 f)There is a syntax error g)There is a runtime error 19
Image of page 19

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
What is the output: a) 7 b) 2 c) ‘c’ Explanation: // means division. 7/3 = 2.333, which is rounded down to 2, since the variables are integers.
Image of page 20
Image of page 21
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern