1. Read and print values of variables of different data types.
CODING:
my_integer=10
my_float=3.14
my_string="hello world"
my_boolean=True
my_list=[1,2,3,4,5]
my_tuple=["apple","banana"]
my_dictionary={"name":"john",
"age":18,
"city":"Chennai"}
print("integer:",my_integer)
print("float:",my_float)
print("string:",my_string)
print("boolean:",my_boolean)
print("list:",my_list)
print("tuple:",my_tuple)
print("dictionary:",my_dictionary)
OUTPUT:
integer: 10
float: 3.14
string: hello world
boolean: True
list: [1, 2, 3, 4, 5]
tuple: ['apple', 'banana']
dictionary: {'name': 'john', 'age': 25, 'city': 'london'
2. Perform arithmetic operation on two integer numbers.
CODING:
num1=input('enter a first number:')
num2=input('enter a second number:')
sum=float(num1)+float(num2)
print('the sum of {0} and {1} is {2}'.format(num1,num2,sum))
sub=float(num1)-float(num2)
print('the sub of {0} and {1} is {2}'.format(num1,num2,sub))
multi=float(num1)*float(num2)
print('the multi of {0} and {1} is {2}';format(num1,num2,mul))
div=float(num1)/float(num2)
print('the div of {0} and {1} is {2}'.format(num1,num2,div))
OUTPUT:
enter a first number:73
enter a second number:10
the sum of 73 and 10 is 83.0
the sub of 73 and 10 is 63.0
the multi of 73 and 10 is 730.0
the div of 73 and 10 is 7.3
3. Find the vowels using conditional statement
CODING:
x=input("Enter a character:")
x=x.lower()
if x=='a' or x=='e' or x=='i' or x=='o' or x=='u':
print("The character is a vowel")
else:
print("The character is not vowel")
OUTPUT:
Enter a character: a
The character is a vowel
4. Calculate the factorial of number using loop
CODING:
num=int(input("enter a character:"))
factorial=1
for i in range(1,num+1):
factorial*=i
print("the factorial of num",factorial)
OUTPUT:
enter a character: 5
the factorial of num 120
5. Calculate the square root of using break, continue and pass
statement
CODING:
import math
while True:
try:
number = float(input("Enter a number: "))
if number < 0:
print("Please enter a non-negative number.")
continue
else:
square_root = math.sqrt(number)
print(f"The square root of {number} is {square_root:.2f}")
break
except ValueError:
print("Invalid input. Please enter a valid number.")
pass
OUTPUT:
Enter a number: 5
The square root of 5.0 is 2.24
6. Check a number is even or odd using return & function statement
CODING:
def check_even_odd(number):
if number% 2==0:
return "even"
else:
return "odd"
number=int(input('enter a number'))
result=check_even_odd(number)
print("The number",number,"is",result)
OUTPUT:
enter a number10
The number 10 is even
7. Fibonacci series using recursion
CODING:
def fibo(n):
if n<=1:
return n
else:
return(fibo(n-1)+fibo(n-2))
nterms=int(input("how many terms?"))
if nterms<=0:
print("please enter positive integer")
else:
print("fibonacci sequence")
for i in range(nterms):
print(fibo(i))
OUTPUT:
How many terms? 10
fibonacci sequence
13
21
34
8. Reverse the order of the items in the array
CODING:
a=input("Enter the element :").split()
b=a[::-1]
print("Reverse array:",b)
OUTPUT:
Enter the element: 3 4 5 6
Reverse array: ['6', '5', '4', '3']
9. Removing the vowels from the string
CODING:
string=input("Enter a string")
vowels=['a','e','i','o','u','A','E','I','O','U']
result=""
for i in range(len(string)):
if string[i]not in vowels:
result=result+string[i]
print("\nAfter removing vowels:",result)
OUTPUT:
Enter a string john
After removing vowels: jhn
10. Remove all duplicates from a list
CODING:
a=input("Enter the element:").split()
b=list(set(a))
print("List without duplicates:",b)
OUTPUT:
Enter the element:1 2 3 1 4 5
List without duplicates: ['2', '1', '5', '4', '3']
11. Tuple that only has positive values from the list
CODING:
def is_pos(number):
return number>0
a=input("Enter the number's:") .split()
a=[int(number)for number in a]
b=tuple(filter (is_pos,a))
print("Tuple with positive number",b)
OUTPUT:
Enter the number's : 1 2 -3 -4 -5 6
Tuple with positive number (1, 2, 6)
12. Creates a dictionary of radius of a circle and its circumference
CODING:
circle_dict = {}
num_circles = int(input("Enter the number of circles: "))
for i in range(num_circles):
radius = float(input(f"Enter the radius of circle {i + 1}: "))
circumference = 2 * 3.14159 * radius
circle_dict[radius] = circumference
print("Dictionary of Circumferences:",circle_dict[radius])
OUTPUT:
Enter the number of circles: 2
Enter the radius of circle 1: 3
Enter the radius of circle 2: 5
Dictionary of Circumferences: 31.4159