Starting from:
$30

$24

Lab 01 Solution

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.




Write a line of code that assigns value 55 to a variable.






Write the code that prints out all numbers from 1 to 20.






Write the code that prints out all even numbers between 1 20.
























Write the code that prints out ten random integers between 1 and 100.















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”,

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”

























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)?

































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?

More products