Que1: Write the Python program to input two numbers and print the sum.
Source code
print("PROGRAM 1")
a=float(input("ENTER NUMBER="))
b=float(input("ENTER NUMBER="))
print("SUM=",a+b)
Output
Que2: Write the python program to check whether the age is valid for vote or
not.
Source code
print("PROGRAM 2")
a=int(input("ENTER YOUR AGE="))
if a>18:
  print("ELIGIBLE TO VOTE!")
elif a<18:
  print("NOT ELIGIBLE TO VOTE!")
else:
  print("INVALID")
Output
Que3: Write a python menu driven program to perform arithmetic
operations.
SOURCE CODE
print("PROGRAM 3")
print("CALCULATOR")
print("Which operation you would like to compute?")
print("[1] to add")
print("[2] to subtract")
print("[3] to multiply")
print("[4] to divide")
c=int(input("ENTER OPERATION:"))
a=float(input("ENTER FIRST NUMBER:"))
b=float(input("ENTER SECOND NUMBER:"))
if c==1:
print("SUM=", a+b)
elif c==2:
  print("SUBTRACTION=", a-b)
elif c==3:
  print("PRODUCT=", a*b)
elif c==4:
  print("QUOTIENT=", a/b)
else:
  print("INVALID")
Output
Que4: Write the python program to check whether the number is even or odd.
SOURCE CODE
print("PROGRAM 4")
a=float(input("ENTER NUMBER="))
if a%2==0:
  print(a,"IS EVEN NUMBER")
else:
  print(a,"IS ODD NUMBER")
Output
Que5: Write the Python program to show implicit and explicit typecasting.
SOURCE CODE [IMPLICIT]
print("PROGRAM 5")
print("IMPLICIT TYPECASTING")
a=float(input("ENTER NUMBER="))
b=float(input("ENTER NUMBER="))
sum=a+b
print(sum)
print(type(sum))
SOURCE CODE [EXPLICIT]
print("PROGRAM 5")
print("EXPLICIT TYPECASTING")
a=float(input("ENTER NUMBER="))
b=float(input("ENTER NUMBER="))
sum=int(a+b)
print(sum)
Output
Que6: Generate the following pattern using nested loops:
*
**
***
****
*****
Source code
for i in range(1,6):
  for j in range(1,i+1):
     print("*",end=" ")
  print()
Output
Que7: Generate the following pattern using nested loops:
12345
1234
123
12
1
Source code
for i in range(5, 0, -1):
   for j in range(1, i + 1):
      print(j, end='')
   print()
Output
Que8: Generate the following pattern using nested loops:
A
AB
ABC
ABCD
ABCDE
Source code
for i in range(65,70):
  for j in range(65,i+1):
     print(chr(j),end=" ")
  print()
Output
Que9: Program to find the sum of the series 1 + x + x^2+ x^3+ .. + x^n by
taking an input of x and n.
Source Code
#PROGRAM 9
x=int(input("ENTER NUMBER="))
n=int(input("ENTER EXPONENT="))
s=1
for i in range (1,n+1):
   s=s+x**i
print("SUM=",s)
Output
Que10: Determine whether a number is a perfect number, an Armstrong
number, or a palindrome.
Source code
#PROGRAM 10
n=int(input("ENTER A NUMBER="))
#perfect number
s=0
for i in range(1,n):
  if n%i==0:
        s=s+i
if s==n:
  print(n,"IS A PERFECT NUMBER")
else:
  print(n,"IS NOT A PERFECT NUMBER")
#armstrong
temp=n
total=0
while temp>0:
  dig=temp%10
  total=total+dig**3
  temp=temp//10
if n==total:
  print(n,"IS ARMSTRONG")
else:
  print(n,"IS NOT ARMSTRONG")
#palindrome
temp=n
rev=0
while n>0:
  dig=n%10
  rev=rev*10+dig
  n=n//10
if temp==rev:
  print("IT IS PALINDROME")
else:
  print("IT IS NOT PALINDROME")
Output
Que11: Input a number and check if the number is a prime or composite
number.
Source code
#PROGRAM 11
n= int(input("ENTER ANY NUMBER="))
if(n ==0 or n == 1):
   print(n,"IS NEITHER COMPOSITE NOR PRIME.")
elif n>1 :
   for i in range(2,n):
      if(n%i == 0):
         print(n,"IS A COMPOSITE NUMBER")
         break
   else:
      print(n,"IS A PRIME NUMBER")
else :
   print("ENTER A POSITIVE INTEGER ")
Que12: Display the terms of a Fibonacci series.
Source Code
#PROGRAM 12
n=int(input("ENTER NUMBER="))
n1,n2=0,1
print("FIBONACCI SERIES=",n1,n2,end=' ')
for i in range(2,n):
   n3=n2+n1
   n1=n2
   n2=n3
   print(n3,end=' ')
print()
Que13: Compute the greatest common divisor and least common multiple of
two integers.
Source Code
n1=int(input("ENTER NUMBER 1="))
n2=int(input("ENTER NUMBER 2="))
gcd=1
if n1%n2==0:
   gcd=n2
else:
   for i in range(n2//2,1,-1):
      if n1%i==0 and n2%i==0:
         gcd=i
         break
print("GCD=",gcd)
lcm=n1*n2/gcd
print("LCM=",lcm)
Que14: Count and display the number of vowels, consonants, uppercase, and
lowercase characters in string.
Source Code
#PROGRAM 14
s=input("ENTER STRING=")
v=ucase=lcase=con=0
for i in s:
   if i=="a" or i=="e" or i=="i" or i=="o" or i=="u":
       v=v+1
   else:
       con=con+1
   if i.isupper():
       ucase=ucase+1
   else:
       lcase=lcase+1
print("NUMBER OF VOWELS IN",s,"=",v)
print("NUMBER OF CONSONANTS IN",s,"=",con)
print("NUMBER OF UPPERCASE IN",s,"=",ucase)
print("NUMBER OF LOWERCASE IN",s,"=",lcase)
Que15: Input a string and determine whether it is a palindrome or not;
convert the case of characters in a string.
Source Code
#PROGRAM 15
s=input("ENTER STRING=")
l=len(s)
res=" "
i=0
j=l-1
for i in range (l):
  if(s[i]==s[j]):
        res=res+s[i]
        j=j-1
  print(s,"IS PALINDROME")
  break
else:
  print(s,"IS NOT PALINDROME")
Que16: Input a list/tuple of elements, and search for a given element
in the list/tuple.
Source Code
l=[]
n=int(input("Enter the number of elements you want in the list="))
for i in range (n):
  e=input("Enter element=")
  l.append(e)
print(l)
print("Searching operation begins")
srch=input("Enter element you want to search=")
f=0
for i in range(n):
  if(l[i]==srch):
       print("Element Found!")
       f=1
       break
if f==0:
  print("Element not found!")
Que17: Input a list of numbers and swap elements at the even location with
the elements at the odd location.
Source Code
l=[]
n=int(input("Enter the number of elements you want in the list="))
for i in range (n):
  e=input("Enter element=")
  l.append(e)
print(l)
print("Swapping process begins!")
i=0
for i in range (0,5,2):
  temp1=l[i]
  temp2=l[i+1]
  l[i],l[i+1]=temp2,temp1
print(l)
Que18: Find the largest/smallest number in a list/tuple.
Source Code
l=[]
n=int(input("Enter the number of elements you want in the list="))
for i in range (n):
   e=input("Enter element=")
   l.append(e)
print(l)
mx=l[0]
for i in l:
        if i>mx:
              mx=i
print(“Largest number=”,mx)
mn=l[0]
for i in l:
   if i<mn:
       mn=i
print("Smallest number=",mn)
Que19: Create a dictionary with the roll number, name, and marks of n
students in a class and display the names of students who
have marks above 75.
Source Code
d={}
n=int(input("Enter number of elements you want="))
for i in range (n):
   rno=int(input("Enter roll no="))
   nm=input("Enter name=")
   mk=int(input("Enter marks="))
   d[rno]=[nm,mk]
print(d)
print("Searching for students who scored more than 75 marks")
for i in d:
   if d[i][1]>75:
      print(d[i][0],"scored more than 75, Bravo!")