Docsity

Python Programming Exercises and Questions - Prof. Randy R. Appleton, Exams of Programming Languages

Toggle sidebar
bg1
Monty Python Test
1) What is the meaning of life?
2) Write me an iterator that produces the powers of -2 for a given count.
Two points for an iterator. One point for a generator.
deadparrot(0) -> []
deadparrot(1) -> [0]
deadparrot(2) -> [1, -2]
deadparrot(3) -> [1, -2, 4]
deadparrot(7) -> [1, -2, 4,-8,16,-32,64]
3) List two advantages and two disadvantages of having dynamic typing.
ADV:____________________________________________________
ADV: ____________________________________________________
DIS: _____________________________________________________
DIS:______________________________________________________
4) Write me a list comprehension that produces the powers of -2 from -20 to -210.
5) Finish this code:
for line in open("/usr/share/dict/words",encoding='latin1').readlines():
for word in line.split():
if
print(word) # only prints words that start with a 'a' and end in a 'z'
6) What is the biggest difference between a list and a set?
pf2

Partial preview of the text

Download Python Programming Exercises and Questions - Prof. Randy R. Appleton and more Exams Programming Languages in PDF only on Docsity!

Monty Python Test

  1. What is the meaning of life?
  2. Write me an iterator that produces the powers of -2 for a given count. Two points for an iterator. One point for a generator. deadparrot(0) -> [] deadparrot(1) -> [0] deadparrot(2) -> [1, -2] deadparrot(3) -> [1, -2, 4] deadparrot(7) -> [1, -2, 4,-8,16,-32,64]
  3. List two advantages and two disadvantages of having dynamic typing. ADV:____________________________________________________ ADV: ____________________________________________________ DIS: _____________________________________________________ DIS:______________________________________________________
  4. Write me a list comprehension that produces the powers of -2 from - 0 to - 10 .
  5. Finish this code: for line in open("/usr/share/dict/words",encoding='latin1').readlines(): for word in line.split(): if print(word) # only prints words that start with a 'a' and end in a 'z'
  6. What is the biggest difference between a list and a set?
  1. Make me a GUI program that looks like the board.
  2. What does this code do? class foo: def init(self): a = 3 def print(self): self.a = 4 print(a) f = foo() f.print()
  3. (Yes/No) Is there some program that can be written using lambda but not without?
  4. What is the difference between from tkinter import * import tkinter
  5. How in Python do you make a class's member variables 'private'?
  6. Given a list 'l', how do I print the third element from the end? For example, from [1,2,3,4,5,6,7,8,9] I want the 7.
  7. Python does not declare variables. Name one advantage of declaring variables.