# addition of numbers using while loop.
#Varibale Declaration
i=1
sum=0
while i<=10: #Checking while loop
sum+=i
i+=1 #Increment of i
#Result
print "The Sum of the numbers upto is ",sum
import sys
#Variable Declaration
i=1
j=0
print "The maximum value of integer is", sys.maxsize
print "The Value of integer after overflow is", sys.maxint-1
#Reverse the given number using while loop
#Variable Declaration
number=digit=rev=0
number=input("Give the Value: ")
while(number!=0):
digit=number%10
rev=rev*10+digit
number= number/10
print "The reversible value of given number is", rev
# Simple interest using while loop.
#Variable Declaration
p=1
n=1
count=1
r=si=0.0
while(count<=3):
p=input("Give the value of P" '\t')
n=input("Give the value of N"'\t')
r=float(input("Give the value of R"'\t'))
si="%.3f"%float((p*n*r)/100)
print "Simple Interest of SI", si
count=count+1
# Numbers upto 10 by using the do..while loop
#Variable Declaration
i=1
sum=0
while True:
sum+=i
i+=1
if(i>10):
break
print "Sum of the numbers upto 10 is", sum
#print n numbers using do...while loop
i=0
n=input("Enter the number: ")
while True:
print "The numbers are: ",i
i=i+1
if(i>=n):
break
#Addition of number upto 10 using for loop
i=sum=0
for i in range (0,11):
sum+=i
i+=1
print "The addition of given numbers",sum
#print n numbers using for...loop structure
n=int(raw_input("Give Values of n: "))
i=0
for i in range(0,n):
print "The Given numbers are: ",i
#student marks and average using for loop..
a=b=c=d=e=total=0
avg=0.0
m=input("Enter the number of Students:")
print "Enter the marks of the five subjects: "'\n'
for i in range (m):
i+=1
print "\nStudent:",i,"\n"
a,b,c,d,e=input("Enter the Student mark1: ")
if ((a,b,c,d,e)!=0) :
total=a+b+c+d+e
avg="%.3f"%float(total/5)
print "Total marks of the student:", total
print "Average marks of the students: ",avg
else :
print "Entered data is invalid"
#Nested for loop
for i in range(1,4):
for j in range(1,4):
print "%d"%(j),
print "\n"
#student details using nested for loop..
FIRST=300
SECOND=200
rollno=marks=total=0
n=input("Enter the number of Students: ")
m=input("Enter the number of subjects: ")
for i in range(n):
i+=(+1)
rollno=int(raw_input("Enter the student roll number: "))
total=0
print "Enter marks of",m, "subjects for Roll no: ",rollno
for j in range(m):
marks=int(raw_input("Give marks: "))
total= total+marks
print "total marks", total
if(total>=FIRST):
print "(First Class)"'\n'
elif(total>=SECOND):
print "(Second Class)"'\n'
else:
print "Fail"
#Demonstrate switch case
a=1
if a==1:
print "I am in case 1"'\n'
elif a==2:
print "I am in case2"'\n'
else:
print "I am in case default"'\n'
#Program to use the computer as calculator
a=b=c=0
op=raw_input("Give the option for calculation like +(ADD), -(SUB), *(MUL), /(DIV): ")
a=input("Enter the value of a ")
b=input("Enter the value of b ")
#Calculation
if (op=='+'):
c=a+b
print "Result of C", c
elif(op=='-'):
c=a-b
print "Result of C", c
elif(op=='*'):
c=a*b
print "Result of C", c
else:
c=a/b
print "Result of C", c
#Find even or odd numbers
#USer Input
a=input("Enter a number: ")
if a%2==0 :
print " The number is even. "
else :
print "The number is odd."
#Program to count number of 0s, 1s, blank spaces and other characters
txt=[30]
count =0
txt=raw_input("Enter Numbers")
print "Total Spaces : %d"%txt.count(' ')
print "Total of 1's : %d"%txt.count('1')
print "Total of 0's : %d"%txt.count('0')
print "String Length : %d"%len(txt)
#Print the number upto 5 using break statement
for i in range(1,10):
if i==6:
break
print i,
#Program to calculate the sum of the given positive numbers
i=n=sum=0
for i in range(0,5):
n=int(raw_input("Give any value of n "))
if n<0:
continue
else:
sum+=n
print "\nSum is", sum
#Program using goto statement
a=input("Give the Value of a ")
b=input("Give the value of b ")
if a==b:
print "A and B are equal"
else:
print "A and B are not equal"
exit(0)
#Prime or not
n=input("Enter the Positive value of n ")
i=2
#Calculation
while n>i:
if n%i==0 & i!=n:
#r=n%i
#if r==0:
print "The Given value of ",n," is not a prime"
break
i+=1
else:
print "The Given Value",n, "is Prime"
#Find the Greatest Common Division
i=int(input("Give the Value of i "))
j=int(input("Give the value of j "))
def gcd(i,j):
if i > j:
k = i%j
if k == 0:
return j
else:
return gcd(j, k)
if i < j:
i = j
j = i
return gcd(i, j)
print "The value of gcd", gcd(i,j)
#Program to which reads in a Temperature and print the temperature in opposite scale
print "1.Fahrenheit to Celcius\n2.Celcius to Fahrenheit\n"
code=input("Choose Option to find Temperature: ")
while code!=0:
if code==1:
f=float(input("Give the Value for Fahrenheit Temperature "))
c=(f-32.0)*5.0/9.0
break
elif code==2:
c=float(input("Give the Value for Celcius Temperature "))
f=9.0*c/5.0+32.0
break
else:
print "Give proper Code Value for Temperature Calculation"
break
print "C=", "%.3f"%float(c)
print "F=",f