A N ( ) I (N) : A Append ( ( ) ) (, (A) ) (, (A) ) : Int Input Range Int Input Print Max Print Min
A N ( ) I (N) : A Append ( ( ) ) (, (A) ) (, (A) ) : Int Input Range Int Input Print Max Print Min
Question 1
Write a Python program to get the largest and smallest number from a list
In [1]: a=[]
n=int(input("Enter the number of numbers in the list"))
for i in range(n):
a.append(int(input("Enter the number")))
print("the biggest number is ",max(a))
print("the smallest number is ",min(a))
Question 2
Write a Python program to count the number of strings where the string length is 2 or more and the first and last
character are same from a given list of strings
There are 2 Strings whose length is two or greater and its first and last c
haracter are same
Question 3
Write a Python function that takes two lists and returns True if they have at least
one common member
Question 4
Write a Python program to print a specified list after removing the 0th, 4th and 5t
h elements
In [5]: a=[]
n=int(input("Enter the number of items in the list(greater than 5): "))
if(n<=5):
print("Invalid input ")
else:
for i in range(n):
a.append(input("enter the item: "))
a.remove(a[5])
a.remove(a[4])
a.remove(a[0])
print(a)
Question 5
Write a Python program to reverse a tuple
Question 6
Write a Python program to convert a tuple to a dictionary
In [1]: a=[]
n=int(input("Enter the number key-value pair in the dictionary "))
for i in range(n):
a.append((input("Enter the key: "),input("Enter the value: ")))
b=dict(a)
print("The tuple is ",tuple(a))
print("The dictionary is",b)
Question 7
Write a Python script to concatenate following dictionaries to create a new one
(i) dic1={1:10, 2:20}
(ii) dic2={3:30, 4:40}
(iii) dic3={5:50,6:60}
In [2]: dic1={1:10,2:20}
dic2={3:30,4:40}
dic3={5:50,6:60}
d={**dic1,**dic2,**dic3}
print("The final dictionary is ",d)
The final dictionary is {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
Question 8
Write a Python script to check whether a given key already exists in a dictionary
In [3]: d={}
n=int(input("Enter the number of key value pair: "))
for i in range(n):
a=input("Enter the key: ")
d[a]=input("Enter the value: ")
a=input("Enter the key you want to search: ")
if(a in d.keys()):
print("YES,",a," is a key of the dictionary")
else:
print("NO,",a,"is not a key of the dictionary")
In [9]: d={}
n=int(input("Enter the number of key value pair: "))
for i in range(n):
a=input("Enter the key: ")
d[a]=input("Enter the value: ")
a=input("Enter the key you want to search: ")
if(a in d.keys()):
print("YES,",a," is a key of the dictionary")
else:
print("NO,",a,"is not a key of the dictionary")
Question 9
Write a Python script to generate and print a dictionary that contains a number (between 1 and n) in the form (x,
x*x)
In [4]: d={}
n=int(input("Enter the number n"))
for i in range(1,n+1):
d[i]=i*i
print("The dictionary is ",d)
Question 10
Write a Python script to print a dictionary where the keys are numbers between 1 and 15 (both included) and the
values are square of keys
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225}
In [5]: d={}
for i in range(1,16):
d[i]=i**2
print("The dictionary is ",d)
Question 11
Write a Python program to print all unique values in a dictionary.
In [7]: d={}
n=int(input("Enter number of items of the dictionary: "))
for i in range (1,n+1):
a=input("Enter the "+str(i)+"th key: ")
d[a] = input("Enter its value: ")
print("The dictionary is ",d)
print("The unique values are",set(d.values()))
Question 12
Write a Python program to remove an item from a set if it is present in the set
In [8]: a=set()
n=int(input("Enter the number of inputs you want to give (need not be equal to
length of set if u duplicate input)"))
for i in range(n):
a.update(input("Enter the item: "))
b=input("Enter the term you want to delete ")
print("The set is ",a)
if(b in a):
a.remove(b)
print("The final set is",a)
else:
print(b,"is not in the set")
Enter the number of inputs you want to give (need not be equal to length of s
et if u duplicate input)4
Enter the item: 1
Enter the item: 2
Enter the item: 3
Enter the item: 4
Enter the term you want to delete 2
The set is {'1', '2', '3', '4'}
The final set is {'1', '3', '4'}
In [10]: a=set()
n=int(input("Enter the number of inputs you want to give (need not be equal to
length of set if u duplicate input)"))
for i in range(n):
a.update(input("Enter the item: "))
b=input("Enter the term you want to delete ")
print("The set is ",a)
if(b in a):
a.remove(b)
print("The final set is",a)
else:
print(b,"is not in the set")
Enter the number of inputs you want to give (need not be equal to length of s
et if u duplicate input)4
Enter the item: 1
Enter the item: 2
Enter the item: 3
Enter the item: 4
Enter the term you want to delete 5
The set is {'1', '4', '2', '3'}
5 is not in the set
Question 13
Write a Python program to find maximum and the minimum value in a set
In [28]: a=[]
n=int(input("Enter the number of terms "))
for i in range(n):
a.append(int(input("Enter the "+str(i+1)+" term")))
a=set(a)
print("The biggest term of the set is ",max(a))
print("The smallest term of the set is",min(a))
Question 14
Write a Python function to reverse a string
Question 15
Write a Python function that accepts a string and calculate the number of upper cas
e letters and lower case letters
for i in a:
if(i.islower()):
l+=1
elif(i.isupper()):
u+=1
else:
pass
return l,u
a=input("Enter the string: ")
v=check(a)
print("There are ",v[0]," Lower case and ",v[1],"Upper case characters")
Question 16
Write a Python function that checks whether a passed string is palindrome or not
Question 17
Write a Python program of recursion list sum
else:
return summer(l,i+1,sum+l[i])
a=[]
n=int(input("Enter the number of terms "))
for i in range(n):
a.append(float(input("Enter the numbers ")))
print(summer(a))
Question 18
Write a Python program to find the greatest common divisor (gcd) of two integers
Question 19
Write a Python program to calculate the value of 'a' to the power 'b