#show the effect of mismatch of data types
#Reads Input value for a
a = raw_input("Enter value of 'A' : ")
a = int(a)
#In python, raw_input() is used to read values
#Result
print "A = ",a
#show the effect of mismatch of data types
import sys
#Variable initialization
#Reads Input value for a
a = raw_input("Enter value of 'A' : ")
a = int(a)
#In python, raw_input() is used to read values
#there is no char datatype of 1 byte size in python.
#python has string variable only.
#Result
sys.stdout.write("A = %d"%(a%256))
#show the effect of various escape sequences
import sys
#Variable initialization
a = 1
b = a + 1
c = b + 1
d = c + 1
#Result
sys.stdout.write ('\tA = %d\nB = %d \'C = %d\''%(a,b,c))
sys.stdout.write ('\n**D = %d**'%(d))
sys.stdout.write ('\nA = %d B = %d'%(a,b))
sys.stdout.write ('\r******')
#print the third power of 2 using pow() function.
#assume the floating point numbers
#Variable initialization
x = 2.0
y = 3.0
#Result
print '%lf raised to %lf is %lf\n' %(x,y,pow(x,y))
#print the third power of 10 using pow() function.
#assume the floating point numbers
#Variable initialization
p = 3
#Result
#There is no pow10() function in Python.
print 'Ten raised to %lf is %lf\n' %(p,pow(10,p))
#detect an error while inputting a data. Use return value of scanf() statement.
#Variable initialization
#in python,the map(int,a.split()) function splits the input characters
#and converts it into integers and returns a value if all the values are integers
#otherwise an exception will be generated and initializes v as 0.
#using exception handling, this result can be achieved.
#Exception handling
try:
a = raw_input("Enter value of 'A','B' & 'C' : ")
v = map(int,a.split())
except:
v = 0
#In python, raw_input() is used to read values
#Result
print '\nError In Inputting.' if v < 3 else '\nValues Successfully read.'
#Find length of the string using print() function
import sys
#Variable initialization
#in python, print()or write() function would not return the number of characters
#written to the output buffer. so len() function is used to find the length.
nm = raw_input("Enter String : ")
#In python, raw_input() is used to read values
l = len(nm)
#Result
print '\nLength = ',l
#Perform addition of two numbers
#Variable initialization
a = raw_input("ENTER TWO VALUES ")
b = raw_input("ENTER TWO VALUES ")
#In python, raw_input() is used to read values
c = int(a) + int(b)
#Result
print '\nSUM IS = ',c
#Find the square of the given number
#Variable initialization
a = raw_input("ENTER ANY NUMBER ")
#In python, raw_input() is used to read values
c = int(a) * int(a)
#Result
print '\nSQUARE OF GIVEN NUMBER = ',c
#Calculate average of three real numbers.
#Variable initialization
a = raw_input("ENTER THREE FLOAT NUMBERS : ")
b = raw_input("ENTER THREE FLOAT NUMBERS : ")
c = raw_input("ENTER THREE FLOAT NUMBERS : ")
#In python, raw_input() is used to read values
d = float(a) + float(b) + float(c)
#Result
print '\nAverage of Given Numbers : ',d/3
#Print message with inputted name
#Variable initialization
yourname = raw_input("Enter Your Name : ")
#In python, raw_input() is used to read values
#Result
print "\nWel Come %s to 'C' Programming Course"%(yourname)
#Input a single character and display it
#Variable initialization
ch = raw_input("Enter any character : ")
#In python, raw_input() is used to read values
#Result
print "\nYour Entered Character is : %c"%(ch)
#Swap the values of two variables without using third variable.
#Variable initialization
a = 7
b = 4
print "\n A = %d B = %d"%(a,b)
#Swapping
a = a + b
b = a - b
a = a - b
#Result
print "Now A = %d B = %d"%(a,b)
#Accept characters through keyboard using getchar() function
import sys
#Variable initialization
#in python, string is an object. It has no nul-termination character.
#raw_input() reads the string constant from the stdin and the write() function
#prints it to the stdout based on the attribute length.
ch = raw_input(" ")
#In python, raw_input() is used to read values
#Result
sys.stdout.write(ch)
#Print the characters using putchar() function
import sys
#Variable initialization
#in python, string is an object. It has no nul-termination character.
#raw_input() reads the string constant from the stdin.
ch = raw_input("Enter Text Here : ")
#In python, raw_input() is used to read values
#Result
#using for loop, the string can be displayed character by character.
sys.stdout.write("The Entered Text : ")
for c in ch:
sys.stdout.write(c)
#Show the effect of getche() and getch() functions
import sys
#Variable initialization
#in python, there is no equivalent function for getche() and getch() functions.
#raw_input() function reads the characters and terminates by pressing the
#enter key
ch = raw_input("Enter any two alphabetics ")
#In python, raw_input() is used to read values
#Result
sys.stdout.write(ch)
#Read and display the character using getch() and putch() functions
import sys
#Variable initialization
#in python, there is no equivalent function for getch() function.
#raw_input() function reads the characters and terminates by pressing the
#enter key
ch = raw_input("Press any key to continue ")
#In python, raw_input() is used to read values
#Result
sys.stdout.write("You Pressed : %s"%(ch))
#Accept string through the keyboard using gets() function
import sys
#Variable initialization
#in python, raw_input() function reads the string and terminates by pressing the
#enter key and write() function displays the string.
ch = raw_input("Enter the String : ")
#In python, raw_input() is used to read values
#Result
sys.stdout.write("Entered String : %s"%(ch))
#Print the accepted character using puts() function
import sys
#Variable initialization
#in python, raw_input() function reads the string and terminates by pressing the
#enter key and print() function displays the string.
ch = raw_input("Enter the String : ")
#In python, raw_input() is used to read values
#Result
print"Entered String : "
print ch
#read string using cgets() and display it using cputs()
import sys
#Variable initialization
#in python, raw_input() function reads the string and terminates by pressing the
#enter key and print() function displays the string.
#in python, string is an object.
t = raw_input("Enter Text Here : ")
#In python, raw_input() is used to read values
#Result
print "Your Entered Text : %s"%(t)