Sei sulla pagina 1di 12

#prime number or not

num=input(enter a number)
If num>1:
For i in range (2,num):
If num % i ==0:
Print (num,is not a prime number)
Break
Else:
Print(num,is a prime number)

# input a number check if the number is positive or negative or zero

num = input("Enter a number: ")


if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")

#program to find factors of a number


def print_factors(x):
print("The factors of",x,"are:")

for i in range(1, x + 1):


if x % i == 0:
print(i)
num = input("Enter a number: ")
Print_factors(num)

#a program to make a simple calculator

print("1: ADDITION")
print("2: SUBTRACTION")
print("3: MULTIPLICATION")
print("4: DIVISION")

CHOICE = raw_input("Enter the choice:")

if CHOICE == "1":
a = input("Enter the value of a:")
b = input("Enter the value of b:")
c=a+b
print c

elif CHOICE == "2":


a = input("Enter the value of a:")
b = input("Enter the value of b:")
c=a-b
print c

elif CHOICE == "3":


a = input("Enter the value of a:")
b = input("Enter the value of b:")
c=a*b
print c

elif CHOICE == "4":


a = input("Enter the value of a:")
b = input("Enter the value of b:")
c=a/b
print c

else:
print "Invalid Number"

#python program to display calendar of the specified month of the year

import calendar
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))
Print calendar.month(yy,mm)

#to convert temperature in degree from celsius to farenheit

celsius = float(input('Enter degree Celsius: '))


fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %
(celsius,fahrenheit))

#to convert temperature in degree from farenheit to celsius


F = input('Enter temperature in Farenhiet')
C = ((5.0/9.0)*(F - 32))
print "Temperature in degreee Celsius is %f" %C

#to check if a number is an armstrong number or not


num = int(input("Enter a number: "))
sum=0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")

#program to accept the principle,rate and interest from the user and
calculate simple interest.
P=input(enter the principle:)
R=input(enter the rate:)

T=input(enter the time:)


Print P*R*T/100

#program to accept radius from user and calculate perimeter and area.
Printto calculate perimeter and area
r=input(enter radius:)
Print area is,3.14*r*
Print perimeter is, 2*3.14*r

#program to find the square and square root of a number .


from math import sqrt,pow
x=input("Enter any number")
y=sqrt(x)
a=pow(x,2)
print "Square Root value =",y
print "square value =",a

#program to find the area of square,rectangle or triangle depending upon the


choice of the user.
print"1. Area of square"
print"2. Area of rectangle"
print"3. Area of triangle"
c = input ("Enter any Choice")
if(c==1):
s = input("enter any side of the square")
a = s*s
print"Area = ",a

elif(c==2):
l = input("enter length")
b = input("enter breadth")
a = l*b
print"Area = ",a
elif(c==3):
x = input("enter first side of triangle")
y = input("enter second side of triangle")
z = input("enter third side of triangle")
s = (x+y+z)/2
A = ((s-x)*(s-y)*(s-z))**0.5
print"Area=",A
else:
print "Wrong input"
# program to print all the natural numbers up to a given number.
n = input("enter any number")
for i in range(1,n+1):
print i,

#program to find the reverse of a number.


n = input("Enter any number")
r=0
while(n>0):
r = r*10+n%10

n = n/10
print "reverse number is", r

#program to count number of uppercase and lowercase letters from a string.


s=raw_input("Enter any String")
print s
u=0
l=0
i=0
while i<len(s):
if (s[i].islower()==True):
l+=1
if (s[i].isupper()==True):
u+=1
i+=1
print "Total upper case letters :", u
print "Total Lower case letters :", l
#to check whether the year entered is a leap year or not.
y =input("enter the year:")
if (y%4==0):
print "Leap Year"
else:
print "Not Leap year"

#Program to implement a stack(using classes)


class stack:

s=[]
def push(self):
a=input("Enter any Number:")
stack.s.append(a)
def display(self):
l=len(stack.s)
if (l==0):
print "Stack Is Empty!"
else:
for i in range(l-1,-1,-1):
print stack.s[i]
a=stack()
c="y"
while(c=="y"):
print "1.PUSH"
print "2.POP"
print "3.DISPLAY"
print "4.EXIT"
choice=input("Enter your choice:")
if (choice==1):
a.push()
elif(choice==2):
if(a.s==[]):
print "Stack Empty"
else:
print "Deleted Element is:",a.s.pop()

elif(choice==3):
a.display()
elif(choice==4):
print "Exiting the program"
else:
print ("Wrong input")
c=raw_input("Do you want to continue?(y/n)")
#eligible to vote or not
age=input("enter your age:")
if age>=18:
print "Eligible to vote"
else:
print "Not eligible to vote"

#program to find the biggest of three numbers


num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))

if (num1 > num2) and (num1 > num3):


largest = num1
elif (num2 > num1) and (num2 > num3):
largest = num2
else:
largest = num3

print("The largest number is",largest)

#program to swap two numbers


x = input('Enter value of x: ')
y = input('Enter value of y: ')
print "The value of x after swapping:",y
print "The value of y after swapping:",x
#fibonacci series
n=input("Enter the number of terms:")
i=0
a=1
b=1
print a
print b
while(i<n-2):
c=a+b
print c
a=b
b=c
i=i+1
#program to find the factorial of a number
num = input("Enter a number: ")
factorial = 1
if num < 0:
print("factorial does not exist for negative numbers")
elif num == 0:

print("The factorial of 0 is 1")


else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
#program to print the sum of first ten natural numbers
sum=0
for i in range(1,11,1):
sum+=i
print sum
# program to print the following pattern
111
222
333
m=input("enter number of rows:")
n=input("enter number of columns:")
for i in range( 1,m+ 1):
for j in range(1,n+1):
print i,
Print
# program to print the following pattern
123
123
123
m=input("enter number of rows:")
n=input("enter number of columns:")

for i in range(1,m+1):
for j in range(1,n+1):
print j,
Print

Potrebbero piacerti anche