num = 8
letter = 'A'
if num > 5:
print "Number exceeds five"
else:
"Number is five or less"
if letter == 'A':
print "Letter is A"
num = 3
if num == 1:
print num," : Monday"
elif num == 2:
print num," : Tuesday"
elif num == 3:
print num," : Wednesday"
elif num == 4:
print num," : Thursday"
elif num == 5:
print num," : Friday"
else:
print "Weekend day"
for i in range(1,4):
print "Loop iteration: ",i
for j in range(1,4):
print " Inner loop iteration: ",j
vec = range(10)
i = 0
print
while i < len(vec):
i = i + 1
if i == 3:
print "| Skipped",
continue
if i == 8:
print "Done"
break
vec[i-1] = i
print "|",vec[i-1],
def bodyTempC():
temperature = 37.0
return temperature
def bodyTempF():
temperature = 98.6
return temperature
print "Centigrade: ",bodyTempC()
print "Fahrenheit: ",bodyTempF()
def fToC(degreesF = 32.0):
degreesC = ((5.0/9.0) * (degreesF - 32.0))
return degreesC
fahrenheit = float(raw_input("Enter a Fahrenheit temperature:\t"))
centigrade = fToC(fahrenheit)
print fahrenheit,"F is ",centigrade,"C"
print "Freezing point: ",fToC(),"C"
def computeArea(diameter):
radius = (diameter/2)
return (3.141593 * (radius * radius))
def computeArea(width,height):
return width * height
def computeArea(letter,width,height):
return ((width/2) * height)
num = float(raw_input("Enter dimension in feet: "))
# python does not support overriding in this way
#area = computeArea(num)
#print "Circle: Area = ",area," sq.ft."
#area= computeArea(num,num)
#print"Square: Area = ",area," sq.ft."
area = computeArea('T',num,num)
print "Triangle: Area = ",area," sq.ft."
def computeFactorials(num,max1):
print "Factorial of ",num,":",
print factorial(num)
num = num + 1
if num > max1:
return 0
else :
computeFactorials(num,max1)
def factorial(n):
if n == 1:
result = 1
else:
result = (factorial(n - 1) * n)
return result
computeFactorials( 1, 8) ;