cs record-1
cs record-1
PROGRAM-1
WAP to read user’s name and print the welcome message
AIM:
To find and print the welcome message
SOURCE CODE:
c=input(“ENTER YOUR NAME:”)
print(“WELCOME”,c)
OUTPUT:
ENTER YOUR NAME:CHARAN TEJA
WELCOME CHARAN TEJA
PROGRAM-2
Write a program to convert the given temperature in centigrade
to Fahrenheit and display.
AIM:
To convert the given temperatue from centigrade to Fahrenheit
SOURCE CODE:
m=int(input("Enter the centrigrade temperature:"))
f=m*(9/5)+32
print("the temperature in Fahrenheit is:",f)
OUTPUT:
Enter the centrigrade temperature:38
the temperature in Fahrenheit is: 100.4
PROGRAM-3
Write a Python program to read three numbers from the user
and find the smallest number.
AIM:
To find the smallest number
SOURCE CODE:
a=int (input ("Enter 1st number: "))
b=int (input ("Enter 2nd number: "))
c=int (input ("Enter 3rd number: "))
if a<b and a<c:
print (a, "is the smallest number")
elif b<a and b<c:
print (b, "is the smallest number")
else:
print (c, "is the smallest number")
OUTPUT:
Enter 1st number: 15
Enter 2nd number: 10
Enter 3rd number: 20
10 is the smallest number
PROGRAM-4
Write a Python program to read a string and check if it is a
palindrome (without using slicing)
AIM:
To read a string and check if it is a palindrome
SOURCE CODE:
a=input("Enter a word")
a=a.lower()
b=""
for i in range(len(a)-1,-1,-1):
b+=a[i]
if b==a:
print (a,"it is a palindrome")
else:
print(a,"it is not a palindrome")
OUTPUT:
Enter a wordcharan
charan is not a palindrome
Enter a wordracecar
racecar it is a palindrome
PROGRAM-5
Write a Python program to read a number and print its
multiplication table till 10
AIM:
To read a number and print its multiplication table till 10
SOURCE CODE:
n=int(input ("Enter a number"))
for i in range(1,11):
print(n,"×",i,n*i)
OUTPUT:
Enter a number25
25 × 1 25
25 × 2 50
25 × 3 75
25 × 4 100
25 × 5 125
25 × 6 150
25 × 7 175
25 × 8 200
25 × 9 225
25 × 10 250
PROGRAM-6
WAP to check if the given number is prime or composite
AIM:
To check if the given number is prime or composite
SOURCE CODE:
a=int (input ("Enter a number: "))
if a==1:
print ("1 is neither a prime nor a composite number")
else:
for i in range (2, a):
if a%i==0:
print (a, "is a Composite")
break
else:
print (a, "is a Prime")
OUTPUT:
Enter a number: 22
22 is a Composite
Enter a number: 13
13 is a Prime
Enter a number: 1
1 is neither a prime nor a composite number
PROGRAM-7
WAP to reverse a number using while loop
AIM:
To reverse a number using while loop
SOURCE CODE:
m=int(input("Enter a number: "))
c=0
while(m!=0):
b=m%10
c=c*10+b
m=m//10
print("The reversed number:",c)
OUTPUT:
Enter a number: 45
The reversed number: 5
The reversed number: 54
PROGRAM-8
WAP to read n(no.of rows) and print the following pattern
1
12
123
1234
12345
AIM:
To print a phyton program that reads the no.of rows and creates its
pattern.
SOURCE CODE:
h=int(input("Enter no.of rows"))
for i in range(1,h+1):
for j in range (1,i+1):
print(j,end="")
print("")
OUTPUT:
1
12
123
1234
12345
123456
PROGRAM-9
WAP to read x,n and find the sum of the series: 1 + 𝑥 +
𝑥2+x3+x4+....xn
AIM:
To read x,n and find the sum of the series 1 + 𝑥 + 𝑥2+x3+x4+....xn
SOURCE CODE:
h=int(input("Enter your x number:"))
n=int(input("Enter your n number:"))
i=1
for i in range(1,n+1):
i+=(h**i)
print("The sum of the series is ",i)
OUTPUT:
Enter your x number:2
Enter your n number:3
The sum of the series is 3
The sum of the series is 6
The sum of the series is 11
PROGRAM-10
Write a menu-based program to perform the four arithmetic
operations of a calculator
AIM:
perform the four arithmetic operations of a calculator
SOURCE CODE:
print("Welcome! Let's do some arithmetic operations.")
while True:
print("\n1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5.
Exit")
opt = int(input("Enter your option: "))
if opt in [1, 2, 3, 4]:
n, a = int(input("Enter first number: ")), int(input("Enter second
number: "))
if opt == 1:
print(f"Result: {n + a}")
elif opt == 2:
print(f"Result: {n - a}")
elif opt == 3:
print(f"Result: {n * a}")
elif opt == 4:
print(f"Result: {n / a if a != 0 else 'Error: Division by zero'}")
elif opt == 5:
if input("Exit? (yes/no): ").lower() in ["yes", "y"]:
break
else:
print("Invalid option.")
OUTPUT:
Welcome! Let’s do some arithmetic operations.
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your option: 4
Enter first number: 6
Enter second number: 3
Result: 2.0
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your option: 1
Enter first number: 2
Enter second number: 2
Result: 4
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your option: 2
Enter first number: 3
Enter second number: 1
Result: 2
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your option: 3
Enter first number: 6
Enter second number: 3
Result: 18
PROGRAM-11
Write a menu based program to perform the following
operations:
A)Fibonacci series till n terms
B) Multiples of n till 50
C) Factorial of a given number
AIM:
To find:
A)Fibonacci series till n terms
B) Multiples of n till 50
C) Factorial of a given number
SOURCE CODE :
while True:
print()
print("""Press 1 to find the Fibonacci series
Press 2 to find the multiples of given number till 50
Press 3 to find the factorial of a given number
Press 4 to Exit""")
print()
opt=int(input("Enter your option: "))
if opt == 1:
n=int(input("Enter the number till you want to print: "))
a=0
b=1
c=0
print(c, end=" ")
for i in range(1,n+1):
a=b
b=c
c=a+b
print(c, end=" ")
elif opt == 2:
n=int(input("Enter the number: "))
a=1
i=1
while a<= 50:
a=n*i
i+=1
if a>50:
break
else:
print(a, end=" ")
elif opt == 3:
a=1
n=int(input("Enter the number: "))
for i in range(1,n+1):
a=a*i
print(a)
elif opt == 4:
print("Bye")
break
else:
print("Invalid Option, enter option again")
continue
Output:
Press 1 to find the Fibonacci series
Press 2 to find the multiples of given number till 50
Press 3 to find the factorial of a given number
Press 4 to Exit
SOURCE CODE:
a=input("Enter your Sentence: ")
u=l=v=c=0
for i in a:
if i.isupper():
u+=1
if i.islower():
l+=1
if i in "AEIOUaeiou":
v+=1
if i not in "AEIOUaeiou" and i.isalpha()==True:
c+=1
print("Number of letters in uppercase:",u)
print("Number of letters in lowercase:",l)
print("Number of letters that are vowels:",v)
print("Number of letters that are consonants:",c)
PROGRAM-13
WAP to input a list of numbers and swap elements at the even
location with the elements at the odd location.
AIM:
To write a program to input a list of numbers and swap
elements at the even location with the elements at the odd
location.
SOURCE CODE:
#Swapping elemnts
l=eval(input("Enter a list of numbers: "))
print(l)
for i in range(0,len(l)-1,2):
l[i],l[i+1]=l[i+1],l[i]
print(l)
OUTPUT:
Enter a list of numbers: [1,2,3,4,5,6]
[1, 2, 3, 4, 5, 6]
Swapped list: [2, 1, 4, 3, 6, 5]
PROGRAM-14
WAP to read a tuple from the user and search for an element given by the
user. Print an appropriate message if the element is not found.
Aim:
To find the given element in a tuple given by the user.
Source code:
M=eval(input("Enter a Tuple: "))
while True:
N=eval(input("Element you want to find: "))
if N in M:
print(N, "is found!!")
else:
print(N, "is not found!!")
P=input("wanna search for another item?")
if P in "YESyes":
continue
else:
print("Byee")
break
Output:
Enter a Tuple: (1,2,3,4,5,6,7,8,9,0,"charan")
Element you want to find: "charan"
Charan is found!!
wanna search for another item?y
Element you want to find: 2
2 is found!!
wanna search for another item?n
Byee
PROGRAM-15
WAP to create a dictionary with the roll number, name, and marks of n
students in a class
Aim:
create a dictionary
Source code:
C= int(input("Number of students: "))
H={}
for i in range(1,c+1):
A=int(input("Enter Roll Number: "))
R=input("Enter the name: ")
N=float(input("Enter marks: "))
if N >= 75:
H[A]=[R,N]
print(H)
Output:
Number of students: 4
Enter Roll Number: 1
Enter the name: A
Enter marks: 43
Enter Roll Number: 2
Enter the name: B
Enter marks: 78
Enter Roll Number: 3
Enter the name: C
Enter marks: 88
Enter Roll Number: 4
Enter the name: D
Enter marks: 94
{2: ['B', 78.0], 3: ['C', 88.0], 4: ['D', 94.0]}
PROGRAM-16
Aim:
count the occurrence of each character using dictionary
Source code:
N=input("Enter you sentence: ")
N=N.upper()
E={}
for i in N:
if i in N:
E[i]+=1
else:
E[i]=1
print(E)
Output:
Enter you sentence: charan
{'c': 1, 'h': 1, 'a': 2, 'r': 1, 'n': 1}
PROGRAM-17
WAP to read a sentence from the user and count the frequency of each
word.
Aim:
To count the frequency of each word
Source code:
I=input("Enter you sentence: ")
I=I.upper()
I=I.split()
S={}
for i in I:
if i in S:
S[i]+=1
else:
S[i]=1
print(S)
Output:
Enter you sentence: baa baa black sheep
{'baa': 2, 'black': 1 , 'sheep': 1}
PROGRAM-18
WAP to count the number of words that start with a capital letter
Aim:
To count the number of words that start with a capital letter
Source code:
H=input("Enter your sentence: ")
H=H.split()
V=0
for i in H:
if i.istitle():
V+=1
print(V)
Output:
Enter your sentence: I am Charan teja
2
PROGRAM-19
Aim:
To simulate the working of title() function
Source code:
s="lets see how the title() function works"
print("Before applying title function:", s)
s=s.split()
m=""
for i in s:
m+=i.capitalize()+ " "
print("After applying title function:", m)
Output:
Before applying title function: lets see how the title() function works
After applying title function: Lets See How The Title() Function Works
PROGRAM-20
WAP to encrypt the given text where in every alphabet must be replaced
by its alternate character.
Aim:
encrypt the given text
Source code:
a=input("Enter the word you want to encrypt: ")
a=a.upper()
b=""
for i in a:
if i.isalpha()==False:
b+=i
elif i =="Y":
b+="A"
elif i =="Z":
b+="B"
else:
char= ord(i)+2
b+=chr(char)
print(b)
Output:
Enter the word you want to encryt: apple
CRRNG