57 solutions available
Question 5Assertion (A): The conditional flow of control can be defined with the help of if statement.Reasoning (R): if statement executes one or...
Question 6Assertion (A): Indexing refers to accessing elements of a sequence. Python offers two types of indexing, viz. positive or forward and...
Question 8Assertion (A): There is no difference between a list and a tuple in Python.Reasoning (R): The list elements are enclosed within square...
Question 2What will be the output of the following code — print("100 + 200") ?300100200100 + 200200
Question 3Which amongst the following is a mutable data type in Python ?intstringtuplelist
Question 7What will be the output generated by the following snippet?a = [5,10,15,20,25] k = 1 i = a [1] + 1 j = a [2] + 1 m = a [k + 1] print (i,...
Question 16Which is the correct form of declaration of dictionary?Day = {1: 'monday', 2: 'tuesday', 3: 'wednesday'}Day = (1; 'monday', 2; ' tuesday',...
Question 18Identify the valid declaration of L:L = {1: 'Mon', 2 : '23', 3: 'hello', 4: '60.5'}dictionarystringtuplelist
Question 21Write the output of the following code:a = 10/2 b = 10//3 print(a, b)5 3.35.0 3.35.0 35 4
Question 1What are the advantages of Python programming language?
Question 4Write Python statement for the following in interactive mode:To display sum of 3, 8.0, 6*12To print sum of 16, 5.0, 44.0
Question 9(i)Write the output of the following:for i in '123': print("CPU", i)
Question 9(ii)Write the output of the following:for i in [100, 200, 300]: print(i)
Question 9(iii)Write the output of the following:for j in range(10, 6, -2): print(j*2)
Question 9(iv)Write the output of the following:for x in range(1, 6): for y in range(1, x+1): print (x, ' ', y)
Question 9(v)Write the output of the following:for x in range(10, 20): if (x == 15): break print(x)
Question 9(vi)Write the output of the following:for x in range(10, 20): if (x % 2 == 0): continue print(x)
Question 10Write the output of the following program on execution if x = 50:if x > 10: if x > 25: print("ok") if x > 60:...
Question 12What are the similarities between strings and lists?
Question 14What is the difference between insert() and append() methods of a list?
Question 15Write a program to calculate the mean of a given list of numbers.Solutionnumbers = eval(input("Enter a list: ")) if len(numbers) == 0:...
Question 17Write a code to calculate and display total marks and percentage of a student from a given list storing the marks of a...
Question 18Write a program to multiply an element by 2 if it is an odd index for a given list containing both numbers and strings.Solutionmixed =...
Question 19Write a program to count the frequency of an element in a list.Solutionmy_list = eval(input("Enter the list: ")) c = int(input("Enter the...
Question 20Write a program to shift elements of a list so that the first element moves to the second index and second index moves to the third index,...
Question 21A list Num contains the following elements:3, 25, 13, 6, 35, 8, 14, 45 Write a program to swap the content with the next value divisible...
Question 22Write a program to accept values from a user in a tuple. Add a tuple to it and display its elements one by one. Also display its maximum...
Question 23Write a program to input any values for two tuples. Print it, interchange it and then compare them.Solutiontuple1 = eval(input("Enter the...
Question 24Write a Python program to input 'n' classes and names of class teachers to store them in a dictionary and display the same. Also accept a...
Question 25Write a program to store student names and their percentage in a dictionary and delete a particular student name from the dictionary. Also...
Question 26Write a Python program to input names of 'n' customers and their details like items bought, cost and phone number, etc., store them in a...
Question 27Write a Python program to capitalize first and last letters of each word of a given string.Solutioninput_string = input("Enter the string:...
Question 28Write a Python program to remove duplicate characters of a given string.Solutioninput_string = input("Enter the string: ") unique_chars =...
Question 29Write a Python program to compute sum of digits of a given number.Solutionnumber = int(input("Enter a number: ")) sum_of_digits = 0 while...
Question 30Write a Python program to find the second most repeated word in a given string.Solutioninput_string = input("Enter the string: ") words =...
Question 31Write a Python program to change a given string to a new string where the first and last characters have been exchanged.Solutioninput_str...
Question 32Write a Python program to multiply all the items in a list.Solutionlst = eval(input("Enter the list: ")) result = 1 for item in lst:...
Question 33Write a Python program to get the smallest number from a list.Solutionnumbers = eval(input("Enter the list: ")) smallest = min(numbers)...
Question 34Write a Python program to append a list to the second list.Solutionlist1 = eval(input("Enter the first list: ")) list2 = eval(input("Enter...
Question 35Write a Python program to generate and print a list of first and last 5 elements where the values are square of numbers between 1 and 30...
Question 36Write a Python program to get unique values from a list.Solutioninput_list = eval(input("Enter the list: ")) unique_values = [] for item...
Question 37Write a Python program to convert a string to a list.Solutionstring = input("Enter the string: ") char_list = list(string) print("String...
Question 38Write a Python script to concatenate the following dictionaries to create a new one:d1 = {'A': 1, 'B': 2, 'C': 3} d2 = {'D': 4 }Output...
Question 39Write a Python script to check if a given key already exists in a dictionary.Solutionmy_dict = eval(input("Enter the dictionary: "))...
Question 40Write a Python script to print a dictionary where the keys are numbers between 1 and 15 (both included) and the values are square of...
Question 41Write a Python script to merge two Python dictionaries.Solutiondict1 = eval(input("Enter the first dictionary: ")) dict2 =...
Question 42Write a Python program to sort a dictionary by key.Solutiondef bubble_sort_keys(keys): n = len(keys) for i in range(n - 1):...
Question 43Write a Python program to combine two dictionaries adding values for common keys.d1 = {'a': 100, 'b': 200, 'c':300} d2 = {'a': 300, 'b':...
Question 44Write a Python program to find the three highest values in a dictionary.Solutionmy_dict = eval(input("Enter the dictionary: "))...
Question 45Write a Python program to sort a list alphabetically in a dictionary.Solutionmy_dict = eval(input("Enter the dictionary: ")) for key,...
Question 46Write a Python program to count number of items in a dictionary value that is a list.Solutionmy_dict = eval(input("Enter the dictionary:...
Question 47Consider the following unsorted list:105, 99, 10, 43, 62, 8.Write the passes of bubble sort for sorting the list in ascending order till...
Question 48What will be the status of the following list after the First, Second and Third pass of the insertion sort method used for arranging the...
Question 49(a)Evaluate the following expression:6 * 3 + 4 ** 2 // 5 - 8
Question 49(b)Evaluate the following expression:10 > 5 and 7 > 12 or not 18 > 3
Question 50What is type casting?
Question 51What are comments in Python? How is a comment different from indentation?