Monday, July 25, 2011

What is the output of phyton from code

What is the output of phyton

# mile/kilometer conversion
for miles in range(10, 70, 10):
    km = miles * 1.609
    print "%d miles --> %3.2f kilometers" % (miles, km)

#

Hints
range work among all numbers
multiplication by float number create float variable
%d digit   %f float


=============
How do you call tiny function

def simplefunction(x):
    print ("functions work!")
    print ("You passed parameter", x)
    z = x**2
    print (x, "squared value =", z)
    return z

Hints
functions need to be called form program to work
some functions need parameters
what error would you get if you call it
simplefunction()
or
simplefunction("Kandy")

======================

What happens here ?

#while loop example
countdown = 10
while countdown:
    print countdown,
    countdown -= 1
print "blasted!"

#

explain each line to your self ?
how many times will the loop run ?
what is the value of countdown at last ?

No comments:

Post a Comment