0% found this document useful (0 votes)
3 views32 pages

Python Spyral

Uploaded by

aramkumar0906
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views32 pages

Python Spyral

Uploaded by

aramkumar0906
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

PYTHON PROGRAMMING

INDEX

S.NO DATE NAME OF THE PROGRAM PAGE NO


1. Sum of Digit
2. Maximum of Three Numbers
3. Armstrong Number
4. Prime Number
5. Palindrome Number Checking
6. Reverse the Number
7. Odd or Even Number Checking
8. Positive or Negative Number Checking
9. Eligible for Vote
10. Perfect Number Checking
11. Factorial using Recursion
12. Print constant in a String
13. Find Largest Number in An Array
14. Array Build-In Function
15. String Build-In Function
16. Biggest among Three Numbers Using
0 Lambda Function
17. Square of Numbers Using Lambda Function
18. Discount Rate Using Default Arguments
19. Multiplication Using Variable Length
Arguments
20. Leap Year Checking Using Modules
21. Fibonacci Sequence Using Modules
22. Multiplication Table Using Modules
23. GCD & LCM of Two Numbers
24. Swapping among Two Numbers
25. Simple Interest
26. Time and Calander
27. Tower of Hanoi
28. Sorting of Numbers Using List
29. List Pre-Defined Function
30. Sum of Numbers Using List
31. Count the occurrence of Sorting
32. Creation of dictionary
33. Creation of dictionary using Key & Values
34. Validate the password Using Dictionary
35. Print Student name &% Using Dictionary
36. Count occurance of Letter Using Dictionary
37.
Ex.No.:1 SUM OF DIGIT
DATE:

AIM:
To write a program of sum of two digits using python.

CODING:
num=int(input("Enter a number:"))
sum=0
while num>0:
digit=num%10
sum+=digit
num//=10
print("sum of digit:",sum)

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No.:2MAXIMUM THREE NUMBERS


DATE:
AIM:
To write a program to find maximum three numbers using python.

CODING:
a=int(input("Enter a value"))
b=int(input("Enter b value"))
c=int(input("Enter c value"))
if(a>b) and (a<c):
print(a,"a is big")
elif(b>c):
print(b,"b is big")
else:
print(c,"c is big")

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No.:3ARMSTRONG NUMBER CHECKING


DATE:

AIM:
To write a program of Armstrong number checking using python.
CODING:
num=int(input("Enter a number:"))
sum=0
temp=num
n=len(str(num))
while temp>0:
digit=temp%10
sum+=digit**n
temp//=10
if sum==num:
print(num,"is an armstrong number")
else:
print(num,"is not an armstrong number")
OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No.:4 PRIME NUMBER CHECKING


DATE:

AIM:
To write a program of prime number checking using python.

CODING:
n=int(input("Enter a number:"))
if n>1:
for i in range(2,n):
if n%i==0:
print(n,"is not prime number")
break
else:
print(n,"is prime number")
else:
print(n,"is not prime number")

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No.:5PALINDROME NUMBER CHECKING


DATE:

AIM:
To write a program to check if the given number is palindrome or not using python.

CODING:
num=int(input("Enter a value for n:"))
temp=num
n=0
while num!=0:
digit=num%10
n=n*10+digit
num=num//10
if temp==n:
print("palindrome number")
else:
print("not palindrome number")

Output:

Result:
Thus the program was successfully executed.

Ex.No.:6REVERSE THE NUMBER


DATE:

AIM:
To write a program to reverse the given number using python.

CODING:
n=int(input("Enter a number:"))
rev_num=0
while n!=0:
digit=n%10
rev_num=rev_num*10+digit
n=n//10
print("Reverse number",rev_num)
OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No.:7 ODD OREVEN NUMBER CHECKING


Date:

AIM:
To write a program to check odd or even of the given number using python.

CODING:
n=int(input("Enter n value:"))
if(n%2==0):
print(n,"is even")
else:
print(n,"is odd")

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No.:8POSITIVE ORNEGATIVE NUMBER CHECKING


DATE:

AIM:
To write a program to check positive or negative of the given number using python.

CODING:
n=int(input("Enter n value"))
if(n>0):
print(n,"is positive")
elif(n==0):
print("no is 0")
else:
print(n,"is negative")
OUTPUT:

RESULT:
Thus the program was successfully executed.
Ex.No.:9ELIGIBLE FOR VOTE
DATE:

AIM:
To write a program to determine weather a person eligible to vote or not.If he/she not eligible show
how many years are left to be eligible.

CODING:
age=int(input("Enter your age:"))
if(age>=18):
print("you are eligible to vote")
else:
yrs=18-age
print("you have to wait another" + str (yrs) + "yeras to cast your vote")

OUTPUT:

RESULT:
Thus the program was successfully executed.
Ex.No.:10PERFECT NUMBER CHECKING
DATE:

AIM:
To write a program to check if the given number is palindrome or not using python.

CODING:
def perf(n):
if n<=0:
return False
d_sum=sum(d for d in range (1,n) if n%d==0)
return d_sum==n
n=int(input("Enter a number:"))
if perf(n):
print("The number is a perfect number")
else:
print("The number is not a perfect number")

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No.:11 FACTORIAL USING RECURSION


DATE:
AIM:
To write a program to print string handling function using python.

CODING:
def factorial(n):
if n<=1:
return 1
else:
return n * factorial(n-1)
n=int(input("Enter the number:" ))
print("Factorial of the number is:",factorial(n))

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No.:12 PRINT CONSONANTS IN A STRING


DATE:

AIM:
To write a program to print string handling function using python.
CODING:

s=input("Enter the string:")


for value in s:
if value=='a' or value=='e' or value=='i' or value=='o' or value=='u':
print(value)

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No.:13 FIND LARGEST NUMBER IN AN ARRAY


DATE:

AIM:
To write a program to print string handling function using python.

CODING:
from array import*
myarray=array('i',[])
n=int(input("Enter the number of elements:"))
print("Enter",n,"numbers:")

for i in range (n):


v=int(input())
myarray.insert(i,v)

m=myarray[0]

for i in range(1,n):
if m<myarray[i]:
m=myarray[i]

print("The largest is",m)

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No.:14ARRAY BUILD-IN FUNCTION


DATE:

AIM:
To write a program to print array build-in functionusing python.
CODING:
from array import *
myarray = array("i", [])

while True:
print("\nMENU")
print("****")
print("1. Creation of array")
print("2. Append")
print("3. Insert")
print("4. Pop")
print("5. Remove")
print("6. Display")

ch = int(input("Enter the choice: "))

if (ch == 1):
myarray = array("i", [])
n = int(input("Enter the number of elements: "))
for i in range(n):
v = int(input("Enter the number: "))
myarray.append(v)
print("Array created successfully...")

elifch == 2:
v = int(input("Enter the number to append: "))
myarray.append(v)
print("Value appended.")

elifch == 3:
v = int(input("Enter the number: "))
i = int(input("Enter the place to insert values: "))
if 0 <= i<= len(myarray):
myarray.insert(i, v)
print("Value inserted.")
else:
print("Invalid Index.")

elifch == 4:
i = int(input("Enter the index to pop: "))
if 0 <= i<len(myarray):
myarray.pop(i)
print("Element popped.")
else:
print("Invalid index.")

elifch == 5:
v = int(input("Enter the element to remove: "))
if v in myarray:
myarray.remove(v)
print("Element removed.")
else:
print("Element not found.")

elifch == 6:
print("Array elements:")
for i in myarray:
print(i, end=" ")
print()

else:
print("Invalid choice.")

c = int(input("Do you want to continue? (Yes=1 / No=0): "))


OUTPUT:

Ex.No.:15STRING HANDLING FUNCTION


DATE:

AIM:
To write a program to print string handling function using python.
CODING:
while True:
print("\nMENU")
print("1. Capitalize the first letter")
print("2. Convert to Uppercase")
print("3. Convert to Lowercase")
print("4. Count characters")
print("5. Exit")
ch = int(input("Enter your choice: "))
if ch in [1, 2, 3, 4]:
s = input("Enter your string: ")
if ch == 1:
print(s.capitalize())
elifch == 2:
print(s.upper())
elifch == 3:
print(s.lower())
elifch == 4:
print(len(s))
elifch == 5:
print("Exiting the program")
break
else:
print("Invalid choice... please try again")

OODING:
RESULT:
Thus the program was successfully executed.

Ex.No.:16 BIGGEST AMONGTHREE NUMBERSUSING LAMBDA FUNCTION


DATE:

AIM:
To write a program to find biggest among three numbers using lambda function using python.

CODING:
a=int(input("Enter a value:"))
b=int(input("Enter b value:"))
c=int(input("Enter c value:"))
if(a>b) and (a<c):
print(a,"a is big")
elif(b>c):
print(b,"b is big")
else:
print(c,"c is big")

OUTPUT:
RESULT:
Thus the program was successfully executed.

Ex.No.:17 SQUARE OFNUMBERS USINGLAMBDA FUNCTION


DATE:

AIM:
To write a program to find square of numbers using lambda function using python.

CODING:
s=lambda n:n*n
print("The square of 12 is:",s(12))
print("The square of 20 is:",s(20))

OUTPUT:

RESULT:
Thus the program was successfully executed.
Ex.No:18 DISCOUNT RATE USING DEFAULT ARGUMENTS
DATE:

AIM:
To write a program to calculate discount rate using default arguments using python.

CODING:
def discount(price,discount_rate=0.03):
discount_amount=price*discount_rate
final_price=price-discount_amount
return final_price
p=int(input("Enter the price:"))
print("The final price of discount rate percent 3 is:",discount(p))
print("The final price of discount rate percent 5 is:",discount(p,0.05))

OUTPUT:

RESULT:
Thus the program was successfully executed.
Ex.No:19 MULTIPLICATION USINGVARIABLE LENGTH ARGUMENTS
DATE:

AIM:
To write a program to multiplication of given numbers using variable length arguments using python.

CODING:
def mul(*num):
m=1
for i in num:
m=m*i
return m # Move return outside the loop

print("The product of the num is:", mul(3, 5, 6, 7))


print("The product of the num is:", mul(2, 4, 5))

OUTPUT:

RESULT:
Thus the program was successfully executed.
Ex.No:20 LEAP YEARCHECKING USING MODULES
DATE:

AIM:
To write a program to check if the given number is leap year or not using modules in python.

CODING:

leap_.py
import leap
year=int(input("Enter the year:"))
leap.leap_year(year)
leap.py
def leap_year(year):
if(year%4==0 and year%100==0)or(year%4==0):
print("Yes!This year is leap year")
else:
print("This is not a leap year")

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:21 FIBONACCI SEQUENCEUSING MODULES


DATE:
AIM:
To write a program to print Fibonacci sequence using python.
CODING:
fibonacci.py
def fibo(num):
a,b=0,1
for x in range (num):
print(a)
a,b=b,a+b
print()
fibo_.py
import fibonacci
num=int(input("Enter the number of fibonacci terms:"))
print("fibonacci sequence:")
fibonacci.fibo(num)
OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:22 MULTIPLICATION TABLEUSING MODULES


DATE:

AIM:
To write a program to print multiplication table using modules.

CODING:
mul.py
def print_table(num):
for x in range(1, 11):
result = num * x
print(num, "*", x, "=", result)
multi_table.py
import mul
num = int(input("Enter the table value: "))
mul.print_table(num)

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:23 GCD*LCM OF TWO NUMBERS


DATE:

AIM:
To write a program to print GCD*LCM of given two numbers using python.

CODING:

from math import gcd


print(gcd(5,25))
def lcm():
a=60
b=40
result=(a*b)//gcd(a,b)
print(result)
lcm()
OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:24 SWAPPING AMONG TWO NUMBERS


DATE:

AIM:
To write a program to swap the given two numbers using python.

CODING:

def swap(a,b):
a,b=b,a
print("After swap:")
print("First number:",a)
print("Second number:",b)
a=int(input("Enter the first number:"))
b=int(input("Enter the second number:"))
print("Before swap:")
print("First number:",a)
print("Second number:",b)
swap(a,b)

OUTPUT:
RESULT:
Thus the program was successfully executed.

Ex.No:25 SIMPLE INTEREST


DATE:

AIM:
To write a program to calculate simple interest of the given numbers using python.

CODING:
def simint(p, y, s):
if s == 'y':
SI = (p * y * 12) / 100
else:
SI = (p * y * 10) / 100
return SI # Moved outside the if-else block

p = float(input("Enter the principal amount: "))


y = float(input("Enter the number of years: "))
senior = input("Is the customer is a senior citizen (y/n): ")

print("Interest:", simint(p, y, senior))

OUTPUT:

RESULT:
Thus the program was successfully executed.
Ex.No:26 TIME AND CALANDER
DATE:

AIM:
To write a program to print current time and calanderusing python.

CODING:

import time
localtime=time.asctime(time.localtime(time.time()))
print("local current time:",localtime)

import calendar
print(calendar.month(2025,7))

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:27 TOWER OF HANOI


DATE:

AIM:
To write a program to print Tower of Hanoi using python.

CODING:

def hanoi(n, A, B, C):


if n > 0:
hanoi(n - 1, A, C, B)
if A:
C.append(A.pop())
hanoi(n - 1, B, A, C)

A = [1,2,3,4]
B = []
C = []

hanoi(len(A), A, B, C)
print(A, B, C)

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:28 SORTING OFNUMBERS USING LIST


DATE:
AIM:
To write the program to sort the given numbers using list in python.

CODING:
list_A=[]
n=int(input("Enter the number of elements:"))
for i in range(n):
ele=input()
list_A.append(ele)
print("Sorting value is:",sorted(list_A))

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:29 LIST PRE-DEFINED FUNCTION


DATE:

AIM:
To write a program for pre-defined function using python.

CODING:
print("list")
c=1
while(c > 0):
print("MENU")
print("****")
print("1.Creation of list")
print("2.Length")
print("3.Search")
print("4.Max and Min")
print("5.Sorting")
print("6.Exit")

ch = int(input("Enter your choice: "))

if ch == 1:
list_A = []
n = int(input("Enter the number of elements: "))
for i in range(n):
ele = int(input("Enter element: "))
list_A.append(ele)
print("List created is:", list_A)

if ch == 2:
print("Length of list is:", len(list_A))

if ch == 3:
sv = int(input("Enter the number to search: "))
if sv in list_A:
print(sv, "is present")
else:
print(sv, "is not present")

if ch == 4:
print("Maximum value is", max(list_A))
print("Minimum value is", min(list_A))

if ch == 5:
print("Sorting value is:", sorted(list_A))

if ch == 6:
print("Exiting the program.")
break

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:30 SUM OFNUMBERS USING LIST


DATE:
AIM:
To write a program to calculate sum of numbers using list.

CODING:
list_A = []
n = int(input("Enter the number of elements: "))
for i in range(n):
ele = int(input("Enter number: "))
list_A.append(ele)
print("The result is:", sum(list_A))

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:31 COUNT THE OCCURENCE OF SORTING


DATE:

AIM:
To write the program to count the occurance of sorting using python.
CODING:

t1=('p','y','t','h','o','n','p','r','o','g','r','a','m')
print(t1)
t2=str(input("Enter the element to check it's occurance:"))
print(t2,"is present in",t1.count(t2),"times in the place of",t1.index(t2))

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:32 CREATION OF DICTIONARY


DATE:

AIM:
To write the program to create the dictionary using python.

CODING:
n=int(input("Enter the number of students:"))
i=0;
dict1={}
while(i<n):
name=input("Enter the name:")
rollno=int(input("Enter the roll number:"))
dict1[name]=rollno
i=i+1
print("Entered dictionary elements are:")
print(dict1)

OUTPUT:

RESULT:
Thus the program was successfully executed.

Ex.No:33 CREATION OFDICTIONARY USING KEY & VALUES


DATE:

AIM:
To write the program to create the dictionary using key and values.

CODING:

employees=dict(input("Enter key and value separated by space:").split()fori in range(2))


print(employees)
OUTPUT:

RESULT:
Thus the program was successfully executed.

You might also like