Computer Project Akriti
Computer Project Akriti
PYTHON ….
INTRODUCTION:
The word python isn’t it scary? Does it bring the image of big
reptile that we prefer to see either in jungles or zoo? Well, it’s
time to change the image. Now on, you’ll remember the word
python for its playfulness and pleasant productivity.
Python programming language was developed by Guido Van Rossum
in February 1991. Python is based on or influenced with two
programming languages:
i = 1
while i <= x:
print()
j=1
while j<= i:
Ans:
x= int (input (" Enter the number "))
i=1
while i<=x:
print ()
j=1
while j<=i :
j+=1
i+=1
3. Write a program to print factorial of a number.
Ans:
num = int (input ("Enter the number : "))
fact = 1
a=1
while a <= num:
fact*=a
a+=1
sum = 0
temp = num
while temp>0:
dig = temp % 10
sum+=dig**order
temp//=10
if num ==sum:
else:
print (num, " is not an Armstrong number ")
sum = 0
temp = num
while temp>0:
dig = temp % 10
sum+=dig**3
temp//=10
if num ==sum:
print (num, " is an Armstrong number")
else:
print (num, " is not an Armstrong number ")
OUTPUT:
5. Write a program to check whether number
is palindrome or not.
Ans:
num = int (input (" Enter number : "))
num1=num
rev = 0
while num1>0:
dig = num1%10
rev = rev *10 +dig
num1//=10
if num==rev:
print (num, "is a palindrome ")
else:
print (num, " is not a palindrome ")
OUTPUT:
6. Write a program to print Fibonacci series.
Ans:
n = int (input (" How many terms? : "))
first = int (input ("Enter the first number : "))
second = int (input (" Enter the second number: "))
print ("\n Fibonacci series is:")
print (first, ",", second, end = " ,")
for i in range (2, n):
next = first + second
print (next, end = " ," )
first = second
second = next
Output:
7. Write a program to check whether a
number is prime or not.
Ans:
num = int (input (" enter any number : "))
if num <= 1:
print (num,"is not a prime number")
else:
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 ")
OUTPUT:
8. Write a program to check number is
positive, zero or negative.
Ans:
number = int (input ("Enter the number :"))
if number<0:
print (number, "is a negative number")
elif number == 0:
print (number, "is equal to zero")
else:
print (number, "is a positive number ")
OUTPUT:
9. Write a program to reverse a number.
Ans:
#python program to reverse a number using while
loop
n = int (input ("Enter the number you want to
reverse : "))
rev = 0
while n>0:
rem = n%10
rev = (rev*10) + rem
n = n//10
print ("reverse number is ", rev)
Output:
10. Write a program to check whether a person
is eligible for vote or not.
Ans:
age = int (input ("Enter your age"))
name = input ("Enter your name ")
if age>=18:
print (name, "Congratulations, you are eligible
for vote")
else:
print (name, "Sorry, you are not eligible for
vote")
OUTPUT:
11. Write a program to check whether year is
leap year or not.
Ans:
year = int (input ("Enter the year"))
if year% 4==0:
print ("Year", year, "is a leap year ")
else:
print ("Year", year, "is not a leap year ")
OUTPUT:
12. Write a program to calculate the salary.
Ans:
salary = int (input ("Enter your salary :"))
name = input ("Enter your name : ")
if salary>= 40000:
bonus =2000
else:
bonus = 1000
gs= salary + bonus
print (name, " , Your salary is ", gs , "and bonus
is ", bonus)
OUTPUT:
13. Write a program to calculate electericity
bill.
Ans:
name=input ("Enter the name")
units=int (input ("enter the units consumed"))
if units <=200:
costperunit=6
amount = units*6
elif units<=300:
costperunit= 7
amount=(200*6) +(units-200) *7
elif units<=400:
costperunit=8
amount=(200*6)+(200*7)-(units-300) *8
else:
costperunit =9
amount= (200*6) +(200*7)+(200*8) -(units-400)*9
print (name, ", Your electricity bill is Rs. ", amount)
OUTPUT:
OUTPUT:
15. Write a program to calculate quadratic
equation: ax2 + bx +c = 0 (a≠0)
Ans:
import math
a=int (input ("Enter the value of a:"))
if a==0:
print ("The value of 'a' cannot be 0. Enter
another value.")
else:
b=int(input("Enter the value of b :"))
c=int(input("Enter the value of c :"))
D=(b**2) -(4*a*c)
if D>0:
X= (-b+math.sqrt(D))/(2*a)
Y= (-b-math.sqrt(D))/(2*a)
print (" The discriminant is ", D," \n so
the real and unequal")
print ("Thus, the roots are: x=", X, "or x
=", Y)
elif D==0 :
X= (-b)/(2*a)
Y= (-b)/(2*a)
print (" The discriminant is ", D," \n so the
real and equal")
print ("Thus, the roots are: x=", X,"or x
=", Y)
else:
print (" The discriminant is ", D," \n so no
real roots exist")
OUTPUT:
16. Write a program to find number of years,
months and days.
Ans:
day=int (input ("enter no. of days"))
y= day//365
r1=day%365
w=r1//30
d=r1%7
print(y,"years",w,"months",d,"days")
OUTPUT:
17. Write a program to find sum of following
series:
i. S = 1 + x + x2 + x3 …+ xn
Ans:
x = int (input ("Enter the value of x:"))
n = int (input ("Enter the value of n (for x**n):"))
s=0
for a in range (n+1):
s+=x**a
print ("sum of first ",n,"terms : ", s)
OUTPUT:
ii. S = 1- x + x2 - x3 +...xn
Ans:
s=0
sign = 1
s+=x**a
sign*= -1
OUTPUT:
iii. S = 1 + x1 + x2 + x3 …+ xn
Ans:
x = int (input ("Enter the value of x:"))
n = int (input ("Enter the value of n (for x**n):"))
s=0
for a in range (n+1):
s+=x**a
print ("sum of first ",n,"terms : ", s)
OUTPUT:
iv. S = x+ x2 /2! - x3 /3! + x4 /4! -...xn /n!
Ans:
x = int (input ("Enter the value of x:"))
n = int (input ("Enter the value of n (for x**n):"))
s=x
sign=1
for a in range (2, n+1):
f=1
for i in range (1, a+1):
f*=i
term = ((x**a) *sign)/f
s+=term
sign*=-1
print ("sum of first ",n,"terms : ", s)
Output:
BIBLOGRAPHY
INTERNET
COMUTER SCIENCE WITH PYTHON BY
SUMITA ARORA