$29.99
A First Round of Python Questions …
To be answered in Lab 1
Based on hour study of programs lets_mingle.py, send.py, and catch_me.py, answer the
following questions or perform the following tasks in the Python programming language.
For some of the question, you may decide to consult online or other sources on Python.
1. Write a line of code that assigns value 55 to a variable.
2. Write the code that prints out all numbers from 1 to 20.
3. Write the code that prints out all even numbers between 1 20.
4. Write the code that prints out ten random integers between 1 and 100.
5. What is the difference between the following two ways of importing modules?
import some_module
and
from some_module import *
6. What is the difference between the following two Python instructions:
print “hello”
and
print “hello”,
7. In the declared graphics window object in catch_me.py with
win = GraphWin("Catch Me!!", 500, 500)
where are the coordinates (0,0) located? (upper left corner, lower left corner,
upper right corner, lower right corner).
8. What is the difference (if there is any) between the following two blocks of code?
if x % 2 == 0:
print “even ”,
print “number”
and
if x % 2 == 0:
print “even “,
print “number”
9. What is the code to define a class Book with data members for the book title, year
of publication and number of pages? What is the instruction that will make variable
mybook be assigned the value of a specific Book objects (your choice)?
10. What is the purpose of the line
if __name__ == '__main__':
in a Python program. The program in catch_me.py features this line, but the program in
lets_mingle.py does not include it. What is going on?