Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

Various python programming exercises and questions covering topics such as iterators, dynamic typing, list comprehension, file i/o, classes, and the difference between lists and sets. It includes tasks like writing an iterator for the powers of -2, listing advantages and disadvantages of dynamic typing, creating a gui program, and understanding the difference between importing and using a module.

Typology: Exams

2009/2010

Uploaded on 02/25/2010

koofers-user-b1o
koofers-user-b1o 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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.