1 Cs
1 Cs
Program–1 :
given character is an alphabet, digit or any other character.
OUTPUT:
Enter a character: 7
7 is a digit
Enter a character: P
P is an alphabet
Write a menu driven program with options to calculate either
Program–2 : factorial of a number or check if the number is prime or
composite.
import math
while True:
print("1. To find factorial")
print("2. To check if prime or not")
print("3. To exit")
ch=int(input("Enter your choice:"))
if ch==1:
num = int(input("Enter any number :"))
fact = 1
n = num # storing num in n for printing
while num>1: # loop to iterate from n to 2
fact = fact * num
num-=1
print("Factorial of ", n , " is :",fact)
elif ch==2:
num = int(input("Enter any number :"))
for i in range(2,int(math.sqrt(num))+1):
if num % i == 0:
print("## Number is not Prime ##")
break
else:
print("## Number is Prime ##")
elif ch==3:
break
OUTPUT:
1. To find factorial
2. To check if prime or not
3. To exit
Enter your choice:1
Enter any number :5
Factorial of 5 is : 120
1. To find factorial
2. To check if prime or not
3. To exit
Enter your choice:2
Enter any number :64
## Number is not Prime ##
1. To find factorial
2. To check if prime or not
3. To exit
Enter your choice:2
Enter any number :23
## Number is Prime ##
1. To find factorial
2. To check if prime or not
3. To exit
Enter your choice:3
Write a program to count lowercase and uppercase letters in an
Program–3 :
inputted string.
OUTPUT:
print(news)
OUTPUT:
Enter string:PythonProgramming
Pythonrgami
Write a program to input a list and sort list elements in
Program–5 :
descending order.
OUTPUT:
t1 = tuple()
n = int(input("Total no of values in first tuple: "))
for i in range(n):
a = input("Enter elements :")
t1 = t1+(a,)
t2 = tuple()
m = int(input("Total no of values in second tuple: "))
for i in range(m):
a = input("Enter elements :")
t2 = t2+(a,)
print("First tuple :")
print(t1)
print("Second tuple :")
print(t2)
t1,t2=t2,t1
print("After swapping :")
print("First tuple: ")
print(t1)
print("Second tuple: ")
print(t2)
OUTPUT:
d={}
while True:
key=input("Enter Product Name:")
value=int(input("Enter Price:"))
d[key]=value
choice=input("Enter More.... (y/n)")
if choice=='n':
break
print(d)
while True:
p=input("Enter Product Name:")
if p in d:
print("Its price is",d[p])
else:
print("product not found")
choice=input("Search More.... (y/n)")
if choice=='n':
break
OUTPUT:
OUTPUT:
for k in d2:
if k not in d3:
d3[k]=d2[k]
else:
d3[k]=d1[k]+d2[k]
print("Original Dictionaries:")
print(d1)
print(d2)
print("Merged Dictionary:")
print(d3)
OUTPUT:
Original Dictionaries:
{'A': 1, 'B': 2, 'C': 3}
{'D': 4, 'B': 4}
Merged Dictionary:
{'A': 1, 'B': 6, 'C': 3, 'D': 4}
Write a program to take 10 sample phishing email, and find the
Program–10 :
most common word occurring.
OUTPUT:
try:
num1=eval(input("Enter dividend = "))
num2=eval(input("Enter divisor = "))
num3 = num1//num2
print("Division performed successfully")
except ZeroDivisionError:
print("Division by zero not allowed")
except NameError:
print("Variable not present")
except:
print("An error has occured")
else:
print ("The quotient is =",num3)
finally:
print("Done!!!!")
OUTPUT:
Enter dividend =
An error has occured
Done!!!!
Enter dividend = 60
Enter divisor = 5
Division performed successfully
The quotient is = 12
Done!!!!
Enter dividend = 60
Enter divisor = 0
Division by zero not allowed
Done!!!!