str1=raw_input('Enter the string 1: ')
str2=raw_input('Enter the string 2: ')
if str1==str2:
print 'String are equal' # It is working based on ascii value refer http://www.ascii-code.com/
elif str1<str2:
print 'Str2 is greater than str1'
elif str1>str2:
print 'Str1 is greater than str2'
elif str1<=str2:
print 'Str1 is greater than or equal to str2'
elif str1>=str2:
print 'Str1 is greater than or equal to str2'
elif str1!=str2:
print 'Str1 is not equal to str2'
Solve Problems by Coding Solutions - A Complete solution for python programming
Converting a for loop to corresponding while loop
for count in range(0,100,2):
print 'For:',count
count1 =0
while(count1<100):
print 'While:',count1
count1=count1+2
print 'For:',count
count1 =0
while(count1<100):
print 'While:',count1
count1=count1+2
Evaluating expression in Python
x=2
y=3
z=2
print x**y**z #Answer 512
print (x**y)**z #Answer 64
print x**(y**z) #Answer 512
y=3
z=2
print x**y**z #Answer 512
print (x**y)**z #Answer 64
print x**(y**z) #Answer 512
Perimeter and area of a circle and finding Natural Exponential Function
import math
r=int(raw_input('Enter the radius of circle:'))
perimeter=2*math.pi*r
print 'Perimeter of a circle :',perimeter
area=math.pi*(r**2)
print 'Area of acircle :',area
x=int(raw_input('Enter the value of x in y=e**x:'))
y=math.e**x
print 'Natural Exponential Function value :',y
r=int(raw_input('Enter the radius of circle:'))
perimeter=2*math.pi*r
print 'Perimeter of a circle :',perimeter
area=math.pi*(r**2)
print 'Area of acircle :',area
x=int(raw_input('Enter the value of x in y=e**x:'))
y=math.e**x
print 'Natural Exponential Function value :',y
Sorting the numbers in the List
L=int(raw_input("Enter the length of list: "))
p=list()
for i in range(L):
num=int(raw_input("Enter the elements : "))
p.append(num)
print '\nUnsorted list is: ',p
for i in range (len(p)):
for j in range (i+1,len(p)):
if p[i]>p[j]:
t=p[i]
p[i]=p[j]
p[j]=t
else:
print '\nSorted List is:' ,p
p=list()
for i in range(L):
num=int(raw_input("Enter the elements : "))
p.append(num)
print '\nUnsorted list is: ',p
for i in range (len(p)):
for j in range (i+1,len(p)):
if p[i]>p[j]:
t=p[i]
p[i]=p[j]
p[j]=t
else:
print '\nSorted List is:' ,p
Subscribe to:
Posts (Atom)