import math
inputs=[5,25,4,8]
Sum,SumSq,SumSqrt=0,0,0
for x in inputs:
Sum+=x
SumSq+=x*x
SumSqrt+=math.sqrt(x)
print " Sum = %d \n SumSq = %d \n SumSqrt = %f" %(Sum,SumSq,SumSqrt)
def main(first,second):
if first>second:
print "first number is bigger"
if second>first:
print "second number is bigger"
if first==second:
print "both are equal"
return
main(5,6)
main(6,5)
main(1,1)
def main(time):
if time>=0. and time<12.:
print "Good Morning"
elif time>=12. and time<18.:
print "Good Afternoon"
elif time>=18. and time<=24.:
print "Good Evening"
else:
print "time is out of range"
return
main(9)
main(15)
main(21)
main(36)
digit=0
while digit<=9:
print digit
digit=digit+1
letter="Fourscore and seven years ago aou fathers brought forth..."
letter=list(letter)
count=0
tag=len(letter)
while count<tag:
letter[count]=letter[count].upper()
count=count+1
letter=''.join(letter)
print letter
Sum,count=0,0
numbers=[1,2,3,4,5,6]
n=6.0
while count<n:
x=numbers[count]
print "x = ",x
Sum+=x
count+=1
average=Sum/n
print 'Average = ',average
digit=0
while True:
print digit
digit=digit+1
if digit>9:
break
letter="Fourscore and seven years ago aou fathers brought forth..."
letter=list(letter)
count=0
tag=len(letter)
while True:
letter[count]=letter[count].upper()
count=count+1
if count>=tag:
break
letter=''.join(letter)
print letter
Sum,count=0,0
numbers=[1,2,3,4,5,6]
n=6.0
while True:
x=numbers[count]
print "x = ",x
Sum+=x
count+=1
if count>=n:
break
average=Sum/n
print 'Average = ',average
for digit in range(0,10):
print digit
letter="Fourscore and seven years ago aou fathers brought forth..."
letter=list(letter)
n=len(letter)
for count in range(0,n):
letter[count]=letter[count].upper()
letter=''.join(letter)
print letter
n=6
Sum=0.0
for count in range(1,n+1):
Sum=Sum+count
average=Sum/n
print "the average is ",average
numbers=[[1.5,2.5,6.2,3.0],[4,-2,7],[5.4,8.0,2.2,1.7,-3.9]]
loopcount=3
loop=0
while loop<loopcount:
Sum=0
for x in numbers[loop]:
print 'x = ',x
Sum+=x
print 'The average is ',Sum/len(numbers[loop])
loop+=1
text=['Now is the time for all good men to come to aid..','Fourscore and seven years ago our fathers brought forth...','*']
loop=0
while True:
letter=text[loop]
if letter=='*':
print "\nGood bye"
break
print '\n',letter
letter=list(letter)
n=len(letter)
for count in range(0,n):
letter[count]=letter[count].upper()
letter=''.join(letter)
print letter
loop+=1
line="The White House. 1600 Pennsylvania Avenue. Washington. DC"
line=list(line)
line2=[]
for count in line:
if (count>='0' and count<'9') or \
(count>='a' and count<'z') or \
(count>='A' and count<'Z'):
line2.extend(chr(ord(count)+1))
elif count=='9':
line2.extend('0')
elif count=='z':
line2.extend('a')
elif count=='Z':
line2.extend('A')
else:
line2.extend('.')
line2=''.join(line2)
print line2
def main(p,r,n):
if p<0 or r<0 or n<0:
print "ERROR! Wrong input"
return
i=r/100.0
f=p*((i+1)**n)
print "The Final value (F) is %.2f" %f
return
main(1000,6,20)
main(5000,-7.5,12)
import math
def main(guess):
count=0
flag=True
while flag:
count=count+1
if count==50:
flag=False
test=10.-3.*guess*guess
if test>0:
root=test**.2
print "Iteration number : %2d x= %7.5f" %(count,root)
error=math.fabs(root-guess)
if error>0.00001:
guess=root
else:
flag=False
print "\n\n root= %7.5f number of iterations %2d" %(root,count)
else:
flag=False
print "number out of range... try another initial guess"
if count==50 and error>0.00001:
print "convergence not obtained after 50 iterations"
return
print "initial guess: 1"
main(1)
print "\ninitial guess: 10"
main(10)
def main(ch):
if ch=='r' or ch=='R':
print "RED"
elif ch=='w' or ch=='W':
print "WHITE"
elif ch=='b' or ch=='B':
print "BLUE"
return
main('r')
main('W')
main('b')
def main(ch):
ch=ch.upper()
if ch=='R':
print "RED"
elif ch=='W':
print "WHITE"
elif ch=='B':
print "BLUE"
else:
print "ERROR"
return
main('r')
main('W')
main('b')
main('y')
import math
def main(x,flag):
if flag==-1:
y=math.fabs(x)
elif flag==0:
y=x**0.5
elif flag==1:
y=x
elif flag==2 or flag==3:
y=2*(x-1)
else:
y=0
print "y= ",y
return
main(36,-1)
main(36,0)
main(36,1)
main(36,2)
main(36,3)
main(36,5)
main(0,6)
choice=0
def main(choice,val,n):
if choice==1:
print "Straight Line Method\n\n"
val=float(val)
deprec=val/n
for year in range(1,n+1):
val=val-deprec
print "End of year %2d Depreciation: %7.2f Current value: %8.2f"\
%(year,deprec,val)
elif choice==2:
print "Double Declining Balance Method\n\n"
val=float(val)
for year in range(1,n+1):
deprec=2*val/n
val=val-deprec
print "End of year %2d Depreciation: %7.2f Current value: %8.2f"\
%(year,deprec,val)
elif choice==3:
print "Sum of the years' -Digit Method\n\n"
val=float(val)
tag=val
for year in range(1,n+1):
deprec=(n-year+1)*tag/(n*(n+1)/2)
val=val-deprec
print "End of year %2d Depreciation: %7.2f Current value: %8.2f"\
%(year,deprec,val)
else:
print "incorrect data entry..."
return
print "\n Method: (1-SSL 2-DDB 3-SYD) "
print "choice: 1 \nval: 8000 \nNumber of years: 10"
main(1,8000,10)
print "\n Method: (1-SSL 2-DDB 3-SYD) "
print "choice: 2 \nval: 8000 \nNumber of years: 10"
main(2,8000,10)
print "\n Method: (1-SSL 2-DDB 3-SYD) "
print "choice: 3 \nval: 8000 \nNumber of years: 10"
main(3,8000,10)
print "\n Method: (1-SSL 2-DDB 3-SYD) "
print "choice: 5 \nval: 8000 \nNumber of years: 10"
main(5,8000,10)
navg=0
Sum=0.0
n=6
for count in range(-6,n+1):
x=count
if(x<0):
continue
Sum=Sum+x
navg=navg+1
average=Sum/navg
print "The average is ",average
def main(letter):
flag=True
letter=list(letter)
tag=len(letter)-1
countback=tag
for count in range(0,(tag/2)+1):
if letter[count]!=letter[countback]:
flag=False
break
countback=countback-1
letter=''.join(letter)
if flag:
print "\n %s IS a palindrome" %letter
else:
print "\n %s is NOT a palindrome" %letter
return
main('TOOT')
main('FALSE')
main('PULLUP')
main('ABLE WAS I ERE I SAW ELBA')
text=['Now is the time for all good men to come to aid..','Fourscore and seven years ago our fathers brought forth.$$..','*']
loop,flag=0,False
while True:
letter=text[loop]
if letter=='*' or flag:
print "\nGood bye"
break
print '\n',letter
letter=list(letter)
n=len(letter)
for count in range(0,n):
letter[count]=letter[count].upper()
letter2=''.join(letter)
print letter2
for count in range(0,n-1):
if letter[count]=='$' and letter[count+1]=='$':
print 'BREAK CONDITION DETECTED - TERMINATE EXECUTION'
flag=True
break
loop+=1