#Print size of various data types using arrays.
import sys
#Variable Initialization
i = [0 for i in range(0,10)]
c = ['0' for i in range(0,10)]
l = [sys.maxint+5 for i in range(0,10)]
#Result
sys.stdout.write("The type 'int' requires %d Bytes"%(sys.getsizeof(int)))
sys.stdout.write("\nThe type 'char' requires %d Bytes"%(sys.getsizeof(str)))
sys.stdout.write("\nThe type 'long' requires %d Bytes"%(sys.getsizeof(long)))
sys.stdout.write("\n%d memory locations are reserved for ten 'int' elements"%(sys.getsizeof(i)))
sys.stdout.write("\n%d memory locations are reserved for ten 'int' elements"%(sys.getsizeof(c)))
sys.stdout.write("\n%d memory locations are reserved for ten 'int' elements"%(sys.getsizeof(l)))
#python data types are different from C
#Display character array with their address.
import sys
#Variable Initialization
name = ['A','R','R','A','Y']
i = 0
#Result
sys.stdout.write("\nCharacter Memory Location\n")
while i < len(name):
sys.stdout.write("\n[%c]\t\t[%d]"%(name[i],id(name[i])))
i += 1
#Find sum of even and odd numbers from 1 to 10.
import sys
#Variable Initialization
sumo = 0
sume = 0
i = 0
a = -1
b = -1
odd = [0 for i in range(0,5)]
even = [0 for i in range(0,5)]
#Calculation
for i in range(1,10+1):
if i%2 == 0:
a += 1
even[a] = i
else:
b += 1
odd[b] = i
#Result
sys.stdout.write("\n\tEven \t\tOdd")
for i in range(0,5):
sys.stdout.write("\n\t %d\t\t %d"%(even[i],odd[i]))
sume = sume + even[i]
sumo = sumo + odd[i]
sys.stdout.write("\n\t==========================\n")
sys.stdout.write("Addition : %d %14d"%(sume,sumo))
#Find sum of even numbers and product of odd numbers from 5 input values.
import sys
#Variable Initialization
a = 0
m = 1
num = [0 for i in range(0,5)]
for i in range(0,5):
sys.stdout.write("\nEnter Number [%d] : "%(i+1))
num[i] = int(raw_input(""))
#Calculation and Result
sys.stdout.write("\n==================================")
for i in range(0,5):
if num[i]%2 == 0:
sys.stdout.write("\nEven Number : %d"%(num[i]))
a = a + num[i]
else:
sys.stdout.write("\nOdd Number : %d"%(num[i]))
m = m * num[i]
sys.stdout.write("\n==================================")
sys.stdout.write("\nAddition of Even Numbers : %d"%(a))
sys.stdout.write("\nProduct of Odd Numbers : %d"%(m))
sys.stdout.write("\n==================================")
#Print string in the reverse order.
import sys
#Variable Initialization
s = ['0' for i in range(0,15)]
s = raw_input("Enter a String : \n")
#Result
sys.stdout.write("Reverse String : \n")
#Since there is no null terminating character for string in python, length of string is taken to give the index range
#index range is given -1 to include the index 0 also.
for i in range(len(s)-1,-1,-1):
sys.stdout.write("%c"%s[i])
#Detect the occurrence of a character in a given string.
import sys
#Variable Initialization
s = ['0' for i in range(0,15)]
c = 0
s = raw_input("Enter a String : ")
f = raw_input("Enter a Character to Find :")
#Calculation
for i in range(0,len(s)):
if s[i] == f:
c += 1
#Result
sys.stdout.write("The Character (%c) in a String (%s) occurs %d times."%(f,s,c))
#Display the elements of two arrays in two separate columns and add their
#corresponding elements and display in the 3rd column.
import sys
#Variable Initialization
num = [24,34,12,44,56,17]
num1 = [12,24,35,78,85,22]
#Result
sys.stdout.write("Element of Array 1st - 2nd Array Addition\n")
for i in range(0,5+1):
sys.stdout.write("\n\t\t%d + %d = %d"%(num[i],num1[i],num[i]+num1[i]))
#Find sum of 3 numbers by entering as character type.
import sys
#Variable Initialization
real = [['0' for i in range(0,6)] for i in range(0,6)]
ima = [['0' for i in range(0,6)] for i in range(0,6)]
for l in range(0,3):
c = int(raw_input("Enter Number : "))
r = c/255
i = c%255
real[l][5] = r
ima[l][5] = i
c = 0
for l in range(0,3):
c = c + real[l][5]*255 + ima[l][5]
sys.stdout.write("\nSum of 3 Numbers : %3ld"%(c))
#Accept any string upto 15 characters. Display the elements of string with their
#element numbers in a separate column.
import sys
#Variable Initialization
#name = ['0' for i in range(0,15)]
name = raw_input("Enter your name : ")
#Result
sys.stdout.write("Element no. & Character\n")
for i in range(0,len(name)): #There is no null termination character for string in python
sys.stdout.write("\n%d \t %c"%(i,name[i]))
#Display names of days of a week
import sys
#Variable Initialization
day = [0 for i in range(0,7)]
sys.stdout.write("Enter numbers between 1 to 7 : ")
for i in range(0,6+1):
day[i] = int(raw_input(""))
#Result
#There is no switch statement in python. use functions and dictionary or if statement instead.
for i in range(0,6+1):
if day[i] == 1:
sys.stdout.write("\n%dst day of week is Sunday"%(day[i]))
else:
if day[i] == 2:
sys.stdout.write("\n%dnd day of week is Monday"%(day[i]))
else:
if day[i] == 3:
sys.stdout.write("\n%drd day of week is Tuesday"%(day[i]))
else:
if day[i] == 4:
sys.stdout.write("\n%dth day of week is Wednesday"%(day[i]))
else:
if day[i] == 5:
sys.stdout.write("\n%dth day of week is Thursday"%(day[i]))
else:
if day[i] == 6:
sys.stdout.write("\n%dth day of week is Friday"%(day[i]))
else:
if day[i] == 7:
sys.stdout.write("\n%dth day of week is Saturday"%(day[i]))
else:
sys.stdout.write("\n%dth is invalid day."%(day[i]))
#Display the contents of two arrays where the 1st array should contain the string and 2nd numerical numbers.
import sys
#Variable Initialization
city = ['N','A','N','D','E','D']
pin = [4,3,1,6,0,3]
#Result
for i in city:
sys.stdout.write("%c"%(i))
sys.stdout.write(" - ")
for i in pin:
sys.stdout.write("%d"%(i))
#Display the number of days of different months of year.
import sys
#Variable Initialization
month = [31,28,31,30,31,30,31,31,30,31,30,31]
#Result
for i in range(0,11+1):
sys.stdout.write("\nMonth [%d] of a year contains %d days."%(i+1,month[i]))
#Display the number of days of given month of a year.
import sys
#Variable Initialization
month = [1,3,5,7,8,10,12,4,6,9,11,2]
mn = int(raw_input("Enter Number of Month : "))
for i in range(0,11+1):
if mn == month[i]: #There is no goto statement in python
if i+1 == 12:
sys.stdout.write("Month (%d) Contains 28 days."%(month[i]))
if i+1 < 8:
sys.stdout.write("Month (%d) Contains 31 days."%(month[i]))
if i+1 > 7 and i+1 != 12:
sys.stdout.write("Month (%d) Contains 30 days."%(month[i]))
#Find the average sales of an item out of 12 months sale.
import sys
#Variable Initialization
#Since sum is a built in function in python, sum1 is used instead of sum.
sum1 = 0
avg = 0
sys.stdout.write("Enter Month No.- Sale of an Item/month\n")
item = [0 for i in range(0,11+1)]
for sale in range(0,11+1):
item[sale] = int(raw_input("\t%d = "%(sale+1)))
#Calculation
for sale in range(0,11+1):
sum1 = sum1 + item[sale]
avg = sum1/12.0
#Result
sys.stdout.write("\nAverage Sale if an item/month = %f"%(avg))
#Find the similar elements in an array and find the occurrence of similar
#numbers for number of times.
import sys
#Variable Initialization
k = 0
j = 1
item = [0 for i in range(0,4+1)]
sys.stdout.write("\nEnter Numbers.\n")
for i in range(0,4+1):
item[i] = int(raw_input("%d = "%(i)))
#Calculation & Result
for j in range(0,4+1):
for i in range(j+1,4+1):
if item[j] == item[i]:
sys.stdout.write("\n%d %d Elements are same."%(j,i))
k += 1
if k == 10:
sys.stdout.write("\nAll elements are same")
else:
if k == 0:
sys.stdout.write("\nNo Elements are same.")
else:
sys.stdout.write("\nElements Contains Double Numbers.")
#Calculate and display total cost of 4 models of Pentium PCs.
import sys
#Variable Initialization
pccode = [1,2,3,4]
t = 0
price = [25000,30000,35000,40000]
stock = [25,20,15,20]
#Result
sys.stdout.write("\nStock & Total Cost Details")
sys.stdout.write("\n========================================================")
sys.stdout.write("\nModel\t\tQty.\tRate(Rs.)\tTotal Value")
sys.stdout.write("\n========================================================")
for i in range(0,3+1):
sys.stdout.write("\nPentium%d\t%d\t%8ld %15ld"%(pccode[i],stock[i],price[i],price[i]*stock[i]))
t = t + price[i] * stock[i]
sys.stdout.write("\n========================================================")
sys.stdout.write("\nTotal Value of All PCs in Rs. %ld"%(t))
sys.stdout.write("\n========================================================")
#Display the given message by using putc() and stdout() functions.
import sys
#Variable Initialization
msg = "C is Easy"
i = 0
#Result
#There is no putc function and null termination in python.
while i < len(msg):
sys.stdout.write("%c"%(msg[i]))
i += 1
#Read the text through keyboard and display it by using
#stdin and stdout streams.
import sys
#Variable Initialization
ch = raw_input("Input a Text : ")
#Result
sys.stdout.write("The Text Entered was\n")
for i in ch:
sys.stdout.write("%c"%(i))
#Sort the given strings alphabetically.
import sys
#Variable Initialization
text = raw_input("Enter Text Below : ")
#Result
sys.stdout.write("Sorted Text Below : \n")
for i in range(65,90+1):
for j in range(0,len(text)):
if text[j] == chr(i).upper() or text[j] == chr(i).lower():
sys.stdout.write("%c"%(text[j]))
#Arrange the numbers in increasing and decreasing order
import sys
#Variable Initialization
sys.stdout.write("Enter ten numbers : ")
a = [0 for i in range(0,10)]
for i in range(0,10):
a[i] = int(raw_input(""))
sum1 = 0
#Calculation
sum1 = sum(a)
#Result
sys.stdout.write("Numbers In Ascending Order : ")
for i in range(0,sum1):
for j in range(0,10):
if i == a[j]:
sys.stdout.write("%3d"%(a[j]))
sys.stdout.write("\nNumbers In Descending Order : ")
for i in range(sum1,0,-1):
for j in range(0,10):
if i == a[j]:
sys.stdout.write("%3d"%(a[j]))
#Sorting in ascending order by comparison method.
import sys
#Variable Initialization
n = int(raw_input("Enter how many numbers to sort : "))
num = [0 for i in range(0,n)]
for i in range(0,n):
num[i] = int(raw_input("Enter numbers # %2d : "%(i+1)))
#Result
sys.stdout.write("The Numbers Entered through keyboard\n")
for i in range(0,n):
sys.stdout.write("%4d"%(num[i]))
for i in range(0,n-1):
for j in range(i+1,n):
if num[i] > num[j]:
temp = num[i]
num[i] = num[j]
num[j] = temp
sys.stdout.write("\nThe Numbers in ascending order\n")
for i in num:
sys.stdout.write("%4d"%(i))
#Evaluate the series contains sum of square of
#numbers from 1 to n.
import sys
#Variable Initialization
s = 0
sqr = [0 for i in range(0,15)]
n = int(raw_input("Enter value of n : "))
for i in range(0,n):
sqr[i] = pow(i+1,2)
for i in range(0,n):
sys.stdout.write("%d\n"%(sqr[i]))
s = s + sqr[i]
sys.stdout.write("Sum of square : %d"%(s))
#Display two dimensional array elements together with their addresses
import sys
#Variable Initialization
a = [[0 for i in range(0,3)]for i in range(0,3)]
c = 1
for i in range(0,3):
for j in range(0,3):
a[i][j] = c
c += 1
#Result
sys.stdout.write("Array Elements and addresses.\n")
sys.stdout.write(" Col-0 Col-1 Col-2\n")
sys.stdout.write("========================================================")
sys.stdout.write("\nRow0")
for i in range(0,3):
for j in range(0,3):
sys.stdout.write(" %d [%5d]"%(a[i][j],id(a[i][j])))
sys.stdout.write("\nRow%d"%(i+1))
sys.stdout.write("\r")
#Display the elements of two-dimensional array.
import sys
#Variable Initialization
a = [[1,2,3],[4,5,6],[7,8,9]]
#Result
sys.stdout.write("Elements of An Array.\n")
for i in range(0,3):
for j in range(0,3):
sys.stdout.write("%5d"%(a[i][j]))
sys.stdout.write("\n")
#Read codenos and balance and count the number of codenos,
#which are having the balance less than 1000.
import sys
#Variable Initialization
j = 0
bal = [[0 for i in range(0,5)]for i in range(0,5)]
for i in range(0,5):
bal[i][1] = int(raw_input("Enter Code No & Balance : "))
bal[i][2] = int(raw_input("Enter Code No & Balance : "))
sys.stdout.write("Your Entered Data : ")
for i in range(0,5):
sys.stdout.write("\n%d %d"%(bal[i][1],bal[i][2]))
if bal[i][2] < 1000:
j += 1
sys.stdout.write("\nBalance Less than 1000 are %d"%(j))
#Accept three elements in a one dimensional array and compute addition,square
#and cube. Display the results in two dimensional array.
import sys
#Variable Initialization
a = [[0 for i in range(0,3)]for i in range(0,3)]
b = [0 for i in range(0,3)]
j = 0
for i in range(0,3):
b[i] = int(raw_input("Enter Three Numbers : "))
#Calculation
for i in range(0,3):
a[i][j] = b[i]*2
a[i][j+1] = pow(b[i],2)
a[i][j+2] = pow(b[i],3)
#Result
sys.stdout.write("Number\tAddition\tSquare\t\tCube\n")
for i in range(0,3):
sys.stdout.write("\n%d"%(b[i]))
for j in range(0,3):
sys.stdout.write("\t%4d\t"%(a[i][j]))
sys.stdout.write("\n")
#Read and display matrix
import sys
#Variable Initialization
a = [[0 for i in range(0,10)]for i in range(0,10)]
row = int(raw_input("Enter Order of matrix upto (10x10) A : "))
col = int(raw_input("Enter Order of matrix upto (10x10) A : "))
for i in range(0,row):
for j in range(0,col):
a[i][j] = int(raw_input("Enter Elements of matrix A : "))
#Result
sys.stdout.write("\nThe Matrix is : \n")
for i in range(0,row):
for j in range(0,col):
sys.stdout.write("%6d"%(a[i][j]))
sys.stdout.write("\n")
#Transpose of matrix
import sys
#Variable Initialization
a = [[0 for i in range(0,10)]for i in range(0,10)]
b = [[0 for i in range(0,10)]for i in range(0,10)]
row1 = int(raw_input("Enter Order of matrix upto (10x10) A : "))
col1 = int(raw_input("Enter Order of matrix upto (10x10) A : "))
for i in range(0,row1):
for j in range(0,col1):
a[i][j] = int(raw_input("Enter Elements of matrix A : "))
row2 = col1
col2 = row1
#Calculation
for i in range(0,row1):
for j in range(0,col1):
b[j][i] = a[i][j]
#Result
sys.stdout.write("\nThe Matrix is : \n")
for i in range(0,row2):
for j in range(0,col2):
sys.stdout.write("%4d"%(b[i][j]))
sys.stdout.write("\n")
#Transpose of 3x3 matrix
import sys
#Variable Initialization
mat = [[0 for i in range(0,3)]for i in range(0,3)]
for i in range(0,3):
for j in range(0,3):
mat[i][j] = int(raw_input("Enter Elements of matrix "))
#Result
sys.stdout.write("Transpose of the matrix\n")
for i in range(0,3):
for j in range(0,3):
sys.stdout.write("\t%d"%(mat[j][i]))
sys.stdout.write("\n")
#Addition and subtraction of two matrices
import sys
#Variable Initialization
a = [[0 for i in range(0,10)]for i in range(0,10)]
b = [[0 for i in range(0,10)]for i in range(0,10)]
r1 = int(raw_input("Enter Order of Matrix A & B upto 10x10"))
c1 = int(raw_input("Enter Order of Matrix A & B upto 10x10"))
for i in range(0,r1):
for j in range(0,c1):
a[i][j] = int(raw_input("Enter Elements of Matrix A:"))
for i in range(0,r1):
for j in range(0,c1):
b[i][j] = int(raw_input("Enter Elements of Matrix B:"))
#Calculation and Result
sys.stdout.write("\nMatrix Addition\n")
for i in range(0,r1):
for j in range(0,c1):
sys.stdout.write("%5d"%(a[i][j]+b[i][j]))
sys.stdout.write("\n")
sys.stdout.write("\nMatrix Subtraction\n")
for i in range(0,r1):
for j in range(0,c1):
sys.stdout.write("%5d"%(a[i][j]-b[i][j]))
sys.stdout.write("\n")
#Multiplication of two matrices
import sys
#Variable Initialization
a = [[0 for i in range(0,10)]for i in range(0,10)]
b = [[0 for i in range(0,10)]for i in range(0,10)]
r1 = int(raw_input("Enter Order of Matrix A & B upto 10x10"))
c1 = int(raw_input("Enter Order of Matrix A & B upto 10x10"))
for i in range(0,r1):
for j in range(0,c1):
a[i][j] = int(raw_input("Enter Elements of Matrix A:"))
for i in range(0,r1):
for j in range(0,c1):
b[i][j] = int(raw_input("Enter Elements of Matrix B:"))
#Calculation and Result
sys.stdout.write("\nMultiplication of corresponding elements\n")
for i in range(0,r1):
for j in range(0,c1):
sys.stdout.write("%5d"%(a[i][j]*b[i][j]))
sys.stdout.write("\n")
#Read the Quantity & Price of various Pentium models using an array and
#Compute the total cost of all models.
import sys
#Variable Initialization
pc = [[0 for i in range(0,4)]for i in range(0,4)]
t = 0
for i in range(0,4):
for j in range(0,2):
pc[i][j] = int(raw_input("Enter Qty. & Price for Pentium %d : "%(i+1)))
#Result
sys.stdout.write("=====================================================")
sys.stdout.write("\nModel\tQty.\tRate(Rs.)\tTotal Value")
sys.stdout.write("\n=====================================================")
for i in range(0,4):
sys.stdout.write("\nPentium %d %2ld %6ld %15ld"%(i+1,pc[i][0],pc[i][1],pc[i][0]*pc[i][1]))
t = t + pc[i][0] * pc[i][1]
sys.stdout.write("\n=====================================================")
sys.stdout.write("\nTotal Value of All PCs in Rs. %ld"%(t))
sys.stdout.write("\n=====================================================")
#Read the capacity of HD, it's price and quantity available in the form of an array
# and compute the cost of HD
import sys
#Variable Initialization
hd = [[0 for i in range(0,4)]for i in range(0,4)]
t = 0
for j in range(0,4):
for i in range(0,3):
hd[i][j] = int(raw_input("Enter Capacity, Price & Qty.:"))
sys.stdout.write("====================================================================\n")
sys.stdout.write("HD Capacity\tGB Price Rs.\tQuantity Total Value Rs.")
sys.stdout.write("\n====================================================================\n")
for j in range(0,4):
for i in range(0,3):
sys.stdout.write("%2ld"%(hd[i][j]))
sys.stdout.write("\t\t")
if i == 2:
sys.stdout.write("%5ld"%(hd[i-1][j]*hd[i][j]))
t = t + hd[i-1][j] * hd[i][j]
sys.stdout.write("\n")
sys.stdout.write("====================================================================")
sys.stdout.write("\nTotal Value Rs. %37ld"%(t))
sys.stdout.write("\n====================================================================")
#Display the names of the cities with their base addresses.
import sys
#Variable Initialization
city = ["Mumbai","Chennai","Kolkata","Pune","Delhi"]
#Result
for i in range(0,5):
sys.stdout.write("Base Address = %u"%(id(city[i]))) #Memory address will differ in different systems
sys.stdout.write("\tString = %s\n"%(city[i]))
#Display the binary bits corresponding to Hexadecimal numbers from
#0 to E and attach an odd parity to Hex numbers and display them.
import sys
#Variable Initialization
bin = [[0 for i in range(0,16)]for i in range(0,16)]
a = 0
c = 0
for x in range(0,16):
y = x
for a in range(0,4):
bin[x][a] = y%2
y = y/2
#Result
sys.stdout.write("\nInput Bits\t Parity Bits")
sys.stdout.write("\n===================================")
for x in range(0,16):
c = 0
sys.stdout.write("\n")
for y in range(3,0-1,-1):
sys.stdout.write("%3d"%(bin[x][y]))
if bin[x][y] == 1:
c += 1
if c%2 == 0:
sys.stdout.write("%7d"%(1))
else:
sys.stdout.write("%7d"%(0))
#Convert binary to gray codes.
import sys
#Variable Initialization
bin1 = [[0 for i in range(0,16)]for i in range(0,16)]
a = 0
c = 0
#Calculation
for x in range(0,16):
y = x
for a in range(0,4):
bin1[x][a] = y%2
y = y/2
#Result
sys.stdout.write("\nBinary Bits\tGray Bits")
sys.stdout.write("\n==================================")
for x in range(0,16):
sys.stdout.write("\n")
for y in range(3,0-1,-1):
sys.stdout.write("%3d"%(bin1[x][y]))
sys.stdout.write("%5d %2d %2d %2d"%(bin1[x][3],(bin1[x][3]^bin1[x][2]),(bin1[x][2]^bin1[x][1]),(bin1[x][1]^bin1[x][0])))
#working of three dimensional array.
import sys
#Variable Initialization
array_3d = [[[0 for i in range(0,3)]for i in range(0,3)]for i in range(0,3)]
for a in range(0,3):
for b in range(0,3):
for c in range(0,3):
array_3d[a][b][c] = a+b+c
#Result
for a in range(0,3):
sys.stdout.write("\n")
for b in range(0,3):
for c in range(0,3):
sys.stdout.write("%3d"%(array_3d[a][b][c]))
sys.stdout.write("\n")
#working of four dimensional array
import sys
#Variable Initialization
array_4d = [[[[0 for i in range(0,2)]for i in range(0,2)]for i in range(0,2)]for i in range(0,2)]
for a in range(0,2):
for b in range(0,2):
for c in range(0,2):
for d in range(0,2):
array_4d[a][b][c][d] = a+b+c+d
#Result
for a in range(0,2):
sys.stdout.write("\n")
for b in range(0,2):
for c in range(0,2):
for d in range(0,2):
sys.stdout.write("%3d"%(array_4d[a][b][c][d]))
sys.stdout.write("\n")
#Read the quantity & rate of certain items using multidimensional
#array. Calculate total cost by multiplying quantity & rate and offer 2%
#discount on it & display the net amount.
import sys
#Variable Initialization
m = [[[[0 for i in range(0,2)]for i in range(0,2)]for i in range(0,2)]for i in range(0,2)]
for a in range(0,2):
for b in range(0,2):
for c in range(0,2):
for d in range(0,1):
if a == 0:
m[a][b][c][d] = int(raw_input("Enter Quantity & Rate\na=%d b=%d c=%d d=%d"%(a,b,c,d)))
m[a][b][c][d+1] = int(raw_input("Enter Quantity & Rate\na=%d b=%d c=%d d=%d"%(a,b,c,d)))
else:
m[a][b][c][d] = m[a-1][b][c][d] * m[a-1][b][c][d+1]
m[a][b][c][d+1] = m[a-1][b][c][d] * m[a-1][b][c][d+1] *2/100
#Result
sys.stdout.write("\n============================================================\n")
sys.stdout.write("Quantity\tRate\tAmoount\tDiscount(@2%)\tNet Amount\n")
sys.stdout.write("============================================================\n")
for a in range(0,1):
for b in range(0,2):
for c in range(0,2):
for d in range(0,1):
sys.stdout.write("\n%10ld %10ld"%(m[a][b][c][d],m[a][b][c][d+1]))
sys.stdout.write("%8ld.00 %6ld.00 %12ld.00"%(m[a+1][b][c][d],m[a+1][b][c][d+1],m[a+1][b][c][d] - m[a+1][b][c][d+1]))
sys.stdout.write("\n============================================================")
#Read string from a character array.
import sys
#Variable Initialization
in1 = raw_input("") #Since in is a keyword in python, in1 is used
#Result
#There is no sscanf() function in python
out = in1
sys.stdout.write("%s\n"%(out))
#Read integers in character array, convert and assign them to integer
#variable.
import sys
#Variable initialization
in1 = raw_input("Enter Integers : ")
#Result
sys.stdout.write("Value of int x : %s"%(in1))
#use of sprintf()
import sys
#Variable Initialization
a = 10
c = 'C'
p = 3.14
spf = str("%d %c %.2f"%(a,c,p)) #There is no sprintf() function in python
sys.stdout.write("\n%s"%(spf))
#Complete the string by filling the spaces with appropriate characters
import sys
#Variable Initialization
name = "Mas er ngA SIC"
name1 = ['' for i in range(0,20)]
x = 0
#Result
sys.stdout.write("Mastering ANSI C\n")
while x < len(name): #There is no null terminating character in python
if name[x] == ' ':
n = raw_input("")
name1[x] = n
else:
name1[x] = name[x]
x += 1
sys.stdout.write("%s"%(name1))