import sys
FormatString=[] #for taking input
a=10
b=20
c=a+b
print 'ok...I have added them: ', a,'+' ,b,'=',c
print 'Now you tell me your format string',
print '(Max 40 characters)'
print 'I will use that to show input numbers',
print 'and their sum'
sys.stdout.flush() #fflush stdin
FormatString='The sum of two numbers'
print FormatString,a,'and',b,'is',c #displaying the numbers and their sum
#variable declaration
value=100
print 'The decimal value is: ',value
print 'The octal value is: ',oct(value)
print 'The hexadecimal value is: ',hex(value)
import math
PI=22.0/7.0
print '123456789012345678901234567890'
print ''
f=0.0
while f<6.28571428:
print '{0:>8.3f}'.format(f), #width(8)
print '{0:>13.4}'.format(math.sin(f)) #width(13)
f+=0.52380952
print ''
print 'sin(2.0*PI)=',math.sin(2.0*PI)
import string
print '1234567890123456789012345678901234567890'
print '{:*>10}'.format(100)
print ''
print '1234567890123456789012345678901234567890'
if(-12.34567>0):
i='{0:>15.3e}'.format(-12.34567) #for ios::scientific
i='+'+i
print i
else :
print '{0:e}'.format(123.23)
i='{0:*>15.3f}'.format(-12.34567) #for ios::scientific
print i
print ''
print '1234567890123456789012345678901234567890'
print '{0:*>+10.3f}'.format(275.5) #for ios::showpos
print ''
print '1234567890123456789012345678901234567890'
print '{:.>5}'.format('n'), #for ios::fill
print '{:.>15}'.format("inverse_of_n"),
print '{:.>15}'.format("sum_of_terms")
sum=0
n=1
for n in xrange(1,11):
term=1.0/float(n)
sum+=term
print '+{:.>5}'.format(n),
print '{:.>14.4f}+'.format(term),
i='{0:.>13.4f}'.format(sum) #for ios::scientific
# i='+'+i
print i
def currency(s):
i='Rs.'
return i
def form(s):
i= '{:.>+10.2f}'.format(s) #showpoint,fill,precision
return i
print currency(1234.5),form(1234.5)
str = raw_input('please input a line of message: ')
print str #display
SIZE=40
line=[]*SIZE
str = raw_input('please input a line terminated by .: ')
if str!='.':
print str #display
infile=open("TEST.txt","r")
#open file for reading
ch=infile.read(1)
while ch != '': #reading file
print ch,
ch=infile.read(1)
infile.close()
data1 = input("Please input a number: ") #user input
data2 = input("Please input another number: ") #user input
print 'Now I will add your numbers:',data1,'and',data2
data3 = data1 + data2
print 'And the result of this addition is:',data3
print 'now I will store all these numbers (comma seperated) \nIn file TEST.txt'
outfile = open('TEST.txt','w')
outfile.write(str(data1)) #writing in file
outfile.write(',')
outfile.write(str(data2))
outfile.write(',')
outfile.write(str(data3))
print 'Now I will close the file TEST.txt'
outfile.close()
print 'Now I will reopen the file TEST.txt'
infile = open('TEST.txt','r')
a = infile.read(len(str(data1))) #reading from file
b = infile.read(1)
c = infile.read(len(str(data2)))
d = infile.read(1)
e = infile.read(len(str(data3)))
print 'value retrieved in first line is',
print a,b,c,d,e
infile.close() #closing the file
print 'And the retrieved data are:'
print a
print c
print e
data1 = input("Please input a number: ") #user input
data2 = input("Please input another number: ") #user input
print 'Now I will add your numbers:',data1,'and',data2
data3 = data1 + data2
print 'And the result of this addition is:',data3
print 'now I will store all these numbers (comma seperated) \nIn file TEST.txt'
outfile = open('TEST.txt','w')
outfile.write(str(data1)) #writing in file
outfile.write(',')
outfile.write(str(data2))
outfile.write(',')
outfile.write(str(data3))
print 'Now I will close the file TEST.txt'
outfile.close()
print 'Now I will reopen the file TEST.txt'
infile = open('TEST.txt','r')
a = infile.read(len(str(data1))) #reading from file
b = infile.read(1)
c = infile.read(len(str(data2)))
d = infile.read(1)
e = infile.read(len(str(data3)))
print 'value retrieved in first line is',
print a,b,c,d,e
infile.close() #closing the file
print 'And the retrieved data are:'
print a
print c
print e