0% found this document useful (0 votes)
4 views24 pages

Cs Record File

The document contains a series of Python programs that perform various tasks, including inputting and manipulating lists, finding largest and smallest numbers, checking for prime and composite numbers, and displaying patterns. Each program is numbered and includes sample outputs to illustrate functionality. The programs cover a wide range of topics suitable for beginners learning Python programming.

Uploaded by

alpnagupta20
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)
4 views24 pages

Cs Record File

The document contains a series of Python programs that perform various tasks, including inputting and manipulating lists, finding largest and smallest numbers, checking for prime and composite numbers, and displaying patterns. Each program is numbered and includes sample outputs to illustrate functionality. The programs cover a wide range of topics suitable for beginners learning Python programming.

Uploaded by

alpnagupta20
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

PROGRAM No – 13

Code

“’[Link] to input a list of numbers from the user and swap elements at the
even location with the odd location”’

L=eval(input("Enter a List"))

if len(L)%2==0:

end=len(L)

else:

end=len(L)-1

print("Original List",L)

for i in range(0,end,2):

L[i],L[i+1]=L[i+1],L[i]

print("List after Swapping",L)

Sample Output
PROGRAM No – 1
Code

#[Link] to input a welcome message and display it

A=input("Enter a welcome message ")

print(A)

Sample Output
PROGRAM No – 2
Code

#[Link] to find the largest and smallest numbers in two given by user

a=int(input("Enter first number: "))

b=int(input("Enter second number: "))

if a>b:

print("Largest number: ",a)

print("Smallest number: ",b)

else:

print("Largest number: ",b)

print("Smallest number: ",a)

Sample Output
PROGRAM No – 3
Code

#[Link] to input three numbers and display the largest and smallest No

num1=int(input("Enter first number: "))

num2=int(input("Enter second number: "))

num3=int(input("Enter third number: "))

if num1>num2 and num1>num3:

print("Largest number ",num1)

elif num2>num1 and num2>num3:

print("Largest number ",num2)

else:

print("Largest number ",num3)

if num1<num2 and num1<num3:

print("Smallest number ",num1)

elif num2<num1 and num2<num3:

print("Smallest number ",num2)

else:

print("Smallest number ",num3)

Sample Output
PROGRAM No – 4
Code

#[Link] to illustrate given patterns

print("Pattern 1")

for i in range(1,6):

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

print("*",end='')

print()

print("Pattern 2")

for i in range(5,0,-1):

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

print(j,end='')

print()

print("Pattern 3")

for i in range(1,6):

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

print(chr(j+64),end='')

print()

Sample Output
PROGRAM No – 5
Code

#[Link] input the value of x and n and print the sum of the given series

print("For Series 1")

x=int(input("Enter the value of x: "))

n=int(input("Enter the value of n: "))

sum=0

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

sum=sum+pow(x,i)/i

print("Sum of series 1: ",1+sum)

print("For Series 2")

x=int(input("Enter the value of x: "))

n=int(input("Enter the value of n: "))

sum=0

for i in range(0,n+1):

if i%2==0:

sum=sum+pow(x,i)

else:

sum=sum-pow(x,i)

print("Sum of series 2: ",sum)


Sample Output
PROGRAM No – 6
Code

#[Link] Driven Program to print Factorial Series,Even Series and Prime Series

opt=0

while True:

print("[Link] series")

print("[Link] series")

print("[Link] series")

print("[Link] Program")

opt=int(input("Enter a Choice: "))

if opt==1:

n=int(input("Enter a number for Factorial Series: "))

fact=1

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

fact*=i

print(fact)

elif opt==2:

n=int(input("Enter a number for Even Series: "))

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

if i%2==0:

print(i)

elif opt==3:

n = int(input("Enter a number for Prime Series: "))

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

fact= 0

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

if i%j == 0:
fact+= 1

if fact == 2:

print(i)

elif opt==4:

print("The Program has been Terminated successfully")

break

else:

print("Invalid choice")

Sample Output
PROGRAM No – 7
Code

#[Link] Driven Program to check for Armstrong ,Perfect ,and Palindrome No

opt = 0

while True:

print("[Link] Armstrong Number")

print("[Link] Perfect Number")

print("3'Check Palindrome Number")

print("[Link] Program")

opt = int(input("Enter Your Choice: "))

if opt == 1:

N = int(input("Enter a number for Armstrong Number Test: "))

d = int(input("Enter number of digits in the number: "))

Sum = 0

n=N

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

DIV = n % 10

Sum += (DIV ** d)

n = (n // 10)

if Sum == N:

print(N, "is an Armstrong Number")

else:

print(N, "is not an Armstrong Number")

elif opt == 2:

n = int(input("Enter a Number for Perfect Number Test: "))

fact = 0

for i in range(1, n):


if n % i == 0:

fact += i

if fact == n:

print(n, "is a perfect number")

else:

print(n, " is not a perfect number")

elif opt == 3:

n = int(input("Enter a Number for Palindrome Number Test: "))

cd=n

temp=n

rev=0

while n>0:

dig=n%10

rev=(rev*10)+dig

n=n//10

if temp==rev:

print(cd,"is a palindrome number")

else:

print(cd,"isn't a palindrome number")

elif opt==4:

print("The Program has been Terminated successfully")

break

else:

print("Invalid choice")
Sample Output
PROGRAM No – 8
Code

#[Link] to determine the number given is prime or composite

num = int(input("Enter a number :"))

count = 0

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

if num % i ==0:

count = count + 1

if count == 2:

print(num,"is prime number")

else:

print(num,"is a composite number")

Sample Output
PROGRAM No – 9
Code

#[Link] to print Fibonacci Series upto n if n is given by user

n= int(input("Enter a number:"))

a=1

b=-1

for i in range(0,n+1):

Sum = (a+b)

b=a

a= Sum

print(Sum)

Sample Output
PROGRAM No – 10
Code

“’[Link] to get the Greatest Common Divisor and Least Common Multiple
of two integers”’

print("For calculating Greatest Common Divisor(GCD) and Least Common


Multiple(LCM): ")

a=int(input("Enter the first number: "))

b=int(input("Enter the second number: "))

if b>a:

mn=a

else:

mn=b

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

if a%i==0 and b%i==0:

gcd=i

print("The Greatest Common Divisor of the given numbers is ",gcd)

if a>b:

maxnum=a

else:

maxnum=b

while(True):

if maxnum%a==0 and maxnum%b==0:

break

maxnum=maxnum+1

print("The Least Common Multiple of the given numbers is ",maxnum)


Sample Output
PROGRAM No – 11
Code

#[Link] Driven Program to do following operations on a List

while True:

print("1. Count the character\n2. Palindrome \n3. convert case \n4. Terminate
program")

a = int(input("select your option: "))

s = input("Enter sentence: ")

if a == 1:

m = "aeiouAEIOU"

v=c=u=l=0

for ch in s:

if [Link]():

if ch in m:

v += 1

else:

c += 1

if [Link](): u += 1

else: l += 1

print(f"Vowels {v}, Consonants {c}, Uppercase: {u}, Lowercase {l}")

elif a == 2:

if s == s[::-1]:

print("Palindrome")

else:

print("Not palindrome")

elif a == 3:

oo = ""
for ch in s:

if [Link]():

oo += [Link]()

elif [Link]():

oo += [Link]()

else:

oo += ch

print("Converted string:", oo)

elif a==4:

print("The Program has been Terminated Successfully")

break

else:

print("Invalid Choice")

Sample Output

s
PROGRAM No-12
Code

#[Link] to do given operations on a list

print("1. Search an element")

print("2. Show largest and smallest element")

print("3. Show sum of elements")

print("4. Terminate program")

a = eval(input("enter list: "))

while True:

choice = int(input("choice: "))

if choice == 1:

k = int(input("enter number to search: "))

if k in a:

print("numberfound ")

else:

print("number not found ")

elif choice == 2:

print("largest number =", max(a))

print("smallest number =", min(a))

elif choice == 3:

print("sum of number =", sum(a))


elif choice == 4:

print("the program has been terminated successfully")

break

else:

print(" number choice")

Sample Output
PROGRAM No – 14
Code

#[Link] to do given operations on a tuple

print("1. Search an element")

print("2. Show largest and smallest element")

print("3. Show sum of elements")

print("4. Terminate program")

a = eval(input("enter tuple: "))

while True:

choice = int(input("choice: "))

if choice == 1:

k = int(input("enter number to search: "))

if k in a:

print("numberfound ")

else:

print("number not found ")

elif choice == 2:

print("largest number =", max(a))

print("smallest number =", min(a))

elif choice == 3:

print("sum of number =", sum(a))


elif choice == 4:

print("the program has been terminated successfully")

break

else:

print(" number choice")

Sample Output
PROGRAM No – 15
Code

“’[Link] a dictionary with the roll number, name and marks of 5students in
a class and display the names of students who have marks above 75.”’

result = {}

for i in range(5):

print("Enter Details of student No.", i+1)

roll_no = int(input("Roll No: "))

std_name = input("Student Name: ")

marks = int(input("Marks: "))

result[roll_no] = [std_name, marks]

print("Dictionary with the details of 5 students")

print(result)

# Display names of students who have got marks more than 75

for student in result:

if result[student][1] > 75:

print("Student's name who get more than 75 marks is",(result[student][0]))


Sample Output

You might also like