Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

1.

Program that takes a number and checks whether the given number
is odd or even
num=int(input("Enter an integer - "))
if num%2==0:
print(num,"is even")
else:
print(num,"is odd")

Enter an integer: 5
5 is odd

2. Program that reads two numbers and an arithmetic operator and


displays the computed result.( 4 function calculator)
a=int (input("Enter the first number:"))
b=int (input("Enter the second number:"))
op=input("Enter operator +, -, *, / : ")
if op == '+':
print("The Result is",a+b)
elif op == '-':
print("The Result is",a-b)
elif op=='*':
print("The Result is",a*b)
elif op=='/':
print("The Result is",a/b)
else:
print("Wrong Operator")
Enter the first number:4 Enter the first number:4
Enter the second number:2 Enter the second number:6
Enter operator +,-,*, /: / Enter operator +,-,*,/: #
The Result is 2.0 Wrong Operator

3. Program to accept three integers and print the largest of the three.
a=float(input("Enter first number"))
b=float(input("Enter second number"))
c=float(input("Enter third number"))
if a==b==c:
print("All numbers are equal")
elif b<a>c: a>b and a>c
print(a,"is the largest")
elif a<b>c:
Enter first number56
print(b,"is the largest")
Enter second number89
else: Enter third number32
print(c,"is the largest") 89 is the largest
4. Program to accept three integers and prints them in ascending order

x=int(input("Enter first number"))


y=int(input("Enter second number"))
z=int(input("Enter third number"))
min=mid=max=0
if x<y and x<z:
if y<z:
min,mid,max=x,y,z
else:
min,mid,max=x,z,y
elif y<x and y<z:
if x<z:
min,mid,max=y,x,z
else:
min,mid,max=y,z,x
else:
if x<y:
min,mid,max=z,x,y
else:
min,mid,max=z,y,x
print("Numbers in Ascending order is:",min,mid,max)

Enter first number 6


Enter second number 4
Enter third number 9
Numbers in Ascending order is: 4 6 9

5. Program to input a number and test if it is a prime number


n=int(input(“Enter a number other than 1: "))
for i in range(2,n):
if n%i==0 :
print(n,"is not a prime number")
break Enter a number other than 1 : 5
else: 5 is a prime number
print(n,"is a prime number")

6. Program to print Fibonacci series


n=int(input("Enter the number of terms"))
f=0
s=1
print(f,end=" ")
print(s,end=" ")
for a in range(3,n+1):
t=f+s
print(t,end=" ") Enter the number of terms: 5
f,s=s,t 01123

7. Program to calculate the factorial of a number


n=int(input("Enter the number"))
fact=1
a=1 Enter the number 5
while a<=n: The factorial of 5 is 120
fact*=a
a+=1
print("The factorial of ", n ,“ is ",fact)

8. Program to find the sum of the series

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


n=int(input("Enter the value of n: "))
s=1 Enter the value of x: 2
for i in range (1,n+1): Enter the value of n: 2
Sum of the series is 7
s+=x**i
print("Sum of the series is",s)

9. Program to read a string and check whether it is a palindrome string


or not.
s=input("Enter a string- ")
if s==s[ : : -1]:
print("It is a Palindrome") Enter a string- malayalam
else: It is a Palindrome
print("It is not a Palindrome")

10. Program to read a line and display the number of uppercase letters,
lowercase letters, alphabets and digits.
s=input("Enter a string-")
up=lo=al=di=0
for i in s: Enter a string-RiYaDh2020
if i.isupper(): Uppercase Letters is 3
up+=1 Lowercase Letters is 3
if i.islower(): Number of Alphabets is 6
lo+=1 Number of digits 4
if i.isalpha():
al+=1
if i.isdigit():
di+=1
print("Uppercase Letters is",up)
print("Lowercase Letters is",lo)
print("Number of Alphabets is",al)
print("Number of digits",di)

11. Write a program in Python to find the average or mean of a given list
of elements.

Enter list elements[1,2,3,4,5]


The mean of numeric values stored in a list is 3.0

12. Write a program in Python to search for an element in the list.

Enter the list elements [5,7,9,45,32,11,65]


Enter the number u want to search 11
The number is present in index 5
13. Write a program in Python to count frequency of a given element in
the list.

Enter the list elements[5,2,4,7,5,1,5,9,5]


Enter the number u want to count 5
The number 5 is present 4 times
14. Write a program to find the smallest and largest number in a list.

Enter the list elements[4,67,34,21,99,100]


The smallest element in the list is 4
The largest element in the list is 100
15. Program to count the frequency of a list elements using a dictionary.
16. Program to count the frequency of each character in a string using a
dictionary OR
Count the number of times a character appears in a given string
using a dictionary

You might also like