PROGRAM 1
INPUT A WELCOME MESSAGE AND DISPLAY IT
a=input(“Enter the welcome message:”)
print(a)
OUTPUT
Enter the welcome message: Welcome to Academic year 2020-21
Welcome to Academic year 2020-21
PROGRAM 2
INPUT TWO NUMBERS AND DISPLAY LARGEST NUMBER/ SMALLEST NUMBER:
a=float(input("Enter first number:"))
b=float(input("Enter second number:"))
if(a>b):
large=a
small=b
else:
large=b
small=a
print("Largest Number:",large)
print("Smallest Number:",small)
OUTPUT
Enter first number:2
Enter second number:1
Largest Number: 2.0
Smallest Number: 1.0
PROGRAM 3
INPUT THREE NUMBERS AND DISPLAY LARGEST NUMBER/ SMALLEST NUMBER:
a=float(input("Enter first number:"))
b=float(input("Enter second number:"))
c=float(input("Enter third number:"))
if(a>b)and(a>c):
larg=a
elif(b>c):
larg=b
else:
larg=c
print("The largest of three numbers is ", larg)
if(a<b)and(a<c):
small=a
elif(b<c):
small=b
else:
small=c
print("The smallest of three numbers is ", small)
OUTPUT
Enter first number:2
Enter second number:3
Enter third number:4
The largest of three numbers is 4.0
The smallest of three numbers is 2.0
PROGRAM 4
GIVE TWO INTEGERS ‘X’ AND ‘N , COMPUTE X N:
x=int(input("Enter first number:"))
n=int(input("Enter second number:"))
y=pow(x,n)
print("The value is",y)
OUTPUT
Enter first number:2
Enter second number:3
The value is 8
5) Write a program to input the value of X & n and print the sum of the
following series.
1)1+X+ 𝑿𝟐 +𝑿𝟑 +…..+𝑿𝒏
n=int(input("enter the number of terms:"))
x=int(input("enter the value of x:"))
sum=1
for i in range(1,n+1):
sum=sum+((x**i))
print("The sum of series is:",round(sum,1))
OUTPUT
enter the number of terms:5
enter the value of x:2
The sum of series is: 63
2)1-X+ 𝑿𝟐 -𝑿𝟑 +…..+𝑿𝒏
n=int(input("enter the number of terms:"))
x=int(input("enter the value of x:"))
sum=1
for i in range(1,n+1):
sum=sum+((x**i)*((-1)**i))
print("The sum of series is:",round(sum,1))
OUTPUT
enter the number of terms:4
enter the value of x:2
The sum of series is: 11
3)X+ 𝑿𝟐 /𝟐-𝑿𝟑 /𝟑+…..+𝑿𝒏 /𝒏
n=int(input("enter the number of terms:"))
x=int(input("enter the value of x:"))
sum=x
for i in range(x,n+1):
sum=sum+(((x**i)/i)*((-1)**i))
print("The sum of series is:",round(sum,1))
OUTPUT
enter the number of terms:4
enter the value of x:2
The sum of series is: 5.3
4)X+ 𝑿𝟐 /𝟐!-𝑿𝟑 /𝟑!+…..+𝑿𝒏 /𝒏!
n=int(input("enter the number of terms:"))
x=int(input("enter the value of x:"))
sum=x
fact=1
for i in range(x,n+1):
fact=fact*i
sum=sum+(((x**i)/fact)*((-1)**i))
print("The sum of series is:",round(sum,1))
OUTPUT
enter the number of terms:3
enter the value of x:2
The sum of series is: 2.7
6)DETERMINE WHETHER NUMBER IS PERFECT NUMBER, ARMSTRONG NUMBER OR
PALINDROME
1) PROGRAM FOR PERFECT NUMBER
num=int(input("enter any number:"))
sum=0
for i in range(1, num):
if num% i==0:
sum=sum+i
if num==sum:
print("it is a perfect number")
else:
print("it is not a perfect number")
OUTPUT
enter any number:6
it is a perfect number
2) PROGRAM FOR ARMSTRONG NUMBER
num=int(input("enter any number:"))
tot=0
temp=num
while temp>0:
dig=temp%10
tot+=dig**3
temp//=10
if num==tot:
print(num,"is an armstrong number")
else:
print(num,"is not an armstrong number")
OUTPUT
enter any number:153
153 is an armstrong number
3) PROGRAM FOR PALINDROME
n=int(input("enter a number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if (temp==rev):
print("the number is palindrome")
else:
print("the number is not palindrome")
OUTPUT
enter a number:222
the number is palindrome
7) INPUT A NUMBER AND CHECK IF THE NUMBER IS PRIME OR COMPOSITE NUMBER
num=int(input("enter any number:"))
isprime= True
for i in range(2,num):
if (num%i)==0:
isprime=False
break
if(isprime):
print(num,"is a prime number")
else:
print(num,"is not a prime number")
OUTPUT
enter any number:17
17 is a prime number
enter any number:4
4 is not a prime number
7) DISPLAY THE TERMS OF FIBONACCI SERIES
num=int(input("enter the value of 'n':"))
a=0
b=1
sum=0
count=1
print("Fibonacci series:",end="")
while(count<=num):
print(sum,end="")
count+=1
a=b
b=sum
sum=a+b
OUTPUT
enter the value of 'n':5
Fibonacci series:01123
9)COMPUTE THE GREATEST COMMON DIVISOR AND LEAST COMMON MULTIPLE OF TWO INTEGERS
x=int(input("enter first number:"))
y=int(input("enter second number:"))
if x>y:
small=y
else:
small=x
for i in range(1,small+1):
if((x%i==0)and (y%i==0)):
hcf=i
lcm=(x*y)/hcf
print("the hcf of",x, "and", y,"is ", hcf)
print("the lcm of",x, "and", y,"is ", lcm)
OUTPUT
enter first number:24
enter second number:36
the hcf of 24 and 36 is 12
the lcm of 24 and 36 is 72.0
10) COUNT AND DISPLAY THE NUMBERS OF VOWELS,CONSONANTS,UPPERCASE,LOWERCASE
CHARACTERS IN STRING
1. TO COUNT UPPERCASE AND LOWERCASE CHARACTER IN STRING
word=input("enter the string:")
uc=lc=0
for a in word:
if a.islower():
lc=lc+1
elif a.isupper():
uc=uc+1
print("number of uppercase letters are:",uc)
print("number of lowercase letters are:",lc)
OUTPUT
enter the string:hello WORLD
number of uppercase letters are: 5
number of lowercase letters are: 5
2. TO COUNT VOWELS AND CONSONANTS IN STRING
str=input("enter the string:")
vc=cc=0
str=str.lower()
for i in range(0,len(str)):
if ( str[i] in ('a','e','i','o','u')):
vc=vc+1
elif (str[i]>='a' and str[i]<='z'):
cc=cc+1
print("number of vowels are:",vc)
print("number of consonants are:",cc)
OUTPUT
enter the string:"This is easy sentence"
number of vowels are: 7
number of consonants are: 11
11)INPUT A STRING AND DETERMINE WHETHER IT IS A PALINDROME OR NOT , CONVERT THE CASE OF
CHARACTERS IN A STRING
str2=input("enter a string:")
rev=str2[::-1]
if(rev==str2):
print("entered string is palindrome")
else:
print("entered string is not palindrome")
if(str2.isupper()):
print(str2.lower())
elif(str2.islower()):
print(str2.upper())
OUTPUT
enter a string:madam
entered string is palindrome
MADAM
enter a string:PYTHON
entered string is not palindrome
python
12)FIND THE LARGEST/SMALLEST NUMBER IN LIST/TUPLE
lst=[]
t=tuple(input("enter the elements for tuple:"))
num=int(input("how many numbers:"))
for n in range(num):
number=int(input("enter numbers for list:"))
lst.append(number)
print("the largest number in list is:",max(lst))
print("the smallest number in list is:", min(lst))
print("the largest number in tuple is:",max(t))
print("the smallest number in tuple is:", min(t))
OUTPUT
enter the elements for tuple:1234
how many numbers:4
enter numbers for list:6
enter numbers for list:7
enter numbers for list:8
enter numbers for list:9
the largest number in list is: 9
the smallest number in list is: 6
the largest number in tuple is: 4
the smallest number in tuple is: 1
13)INPUT A LIST OF NUMBERS AND SWAP ELEMENTS AT EVEN LOCATION WITH ELEMENTS AT ODD
LOCATION
x=eval(input("enter the list:"))
evenpos=[]
oddpos=[]
for i in range(0,len(x)):
if i%2==0:
evenpos.append(x[i])
else:
oddpos.append(x[i])
temp=evenpos
evenpos=oddpos
oddpos=temp
print("The element of evenpos after swapping:",evenpos)
print("the element of oddpos after swapping:",oddpos)
OUTPUT
enter the list:[2,4,6,8,10]
The element of evenpos after swapping: [4, 8]
the element of oddpos after swapping: [2, 6, 10]
14)INPUT A LIST/TUPLE OF ELEMENTS , SEARCH FOR GIVEN ELEMENT IN LIST/TUPLE
lst=eval(input("enter list:"))
length=len(lst)
element=int(input("enter element to be searched for:"))
for i in range(0,length-1):
if element==lst[i]:
print(element,"found at index",i)
break
else:
print(element,"not found in given list")
OUTPUT
enter list:[2,4,5,6,7]
enter element to be searched for:5
5 found at index 2
15)INPUT A LIST OF NUMBERS AND TEST IF A NUMBER IS EQUAL TO SUM OF CUBES OF ITS DIGIT. FIND
SMALLEST AND LARGEST SUCH NUMBER FROM GIVEN LIST OF NUMBERS
lst=[]
num=int(input("how many numbers:"))
for n in range(num):
number=int(input("enter number:"))
lst.append(number)
for i in range(len(lst)):
temp=lst[i]
sum=0
while(temp>0):
digit=temp%10
sum+=digit**3
temp//=10
if (lst[i]==sum):
print(lst[i],"is equal to sum of cubes of digit")
else:
print(lst[i],"is not equal to sum of cubes of digit")
print("the smallest number in given list is",min(lst))
print("the largest number in given list is",max(lst))
OUTPUT
how many numbers:2
enter number:371
enter number:407
371 is equal to sum of cubes of digit
407 is equal to sum of cubes of digit
the smallest number in given list is 371
the largest number in given list is 407
16)CREATE A DICTIONARY WITH ROLL NUMBER,NAME AND MARKS OF n STUDENTS IN A CLASS AND
DISPLAY THE NAMES OF STUDENTS WHO HAVE MARKS ABOVE 75
n=int(input("enter number of student:"))
student_data=["student_name","student_rollno","mark1"]
for i in range(0,n):
student_name=input("enter name of student:")
student_rollno=int(input("enter the rollno of student:"))
mark1=int(input("enter marks of student for 100:"))
dict={'name':student_name,'rollno':student_rollno,'mark1':mark1}
if(int(mark1)>75):
print(dict['name'],"is having more than 75")
else:
print(dict['name'], "is not having more than 75")
OUTPUT
enter number of student:2
enter name of student:RAM
enter the rollno of student:1234
enter marks of student for 100:88
RAM is having more than 75
enter name of student:RAJ
enter the rollno of student:6789
enter marks of student for 100:44
RAJ is not having more than 75