0% found this document useful (0 votes)
54 views10 pages

Lab Questions Mix Up 11-06-2024

The document contains a comprehensive list of Python programming tasks, ranging from basic operations like printing multiplication tables and checking for palindromes, to more complex tasks such as calculating bonuses based on salary and determining leap years. Each task is designed to enhance programming skills through practical applications of Python concepts, including the use of dictionaries, loops, and conditionals. The tasks cater to various levels of difficulty, making it suitable for learners at different stages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views10 pages

Lab Questions Mix Up 11-06-2024

The document contains a comprehensive list of Python programming tasks, ranging from basic operations like printing multiplication tables and checking for palindromes, to more complex tasks such as calculating bonuses based on salary and determining leap years. Each task is designed to enhance programming skills through practical applications of Python concepts, including the use of dictionaries, loops, and conditionals. The tasks cater to various levels of difficulty, making it suitable for learners at different stages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Write a Python program that prompts the user to input a number and prints its
multiplication table.
2. Write a python program to print the name of a student by getting roll number as input.
(Use dictionaries)

3. Write a Python program to print the first 8 terms of an arithmetic progression starting
with 3 and having a common difference of 4. The program should output the
following sequence:
3 7 11 15 19 23 27 31
4. Write a Python script to generate and print a dictionary that contains a number
(between 1 and n) in the form (x, x*x).

5. Write a Python program to check whether an integer is a palindrome.


6. Write a Python program to enter names of employees and their salaries as input and
store them in a dictionary. Print the employee name who is paid the highest salary.

7. Write a Python program that takes a positive integer N as input and calculates the sum
of the reciprocals of all numbers from 1 up to N. The program should display the final
sum. Output of the program should be like:
Enter a positive integer: 5
The sum of reciprocals from 1 to 5 is: 2.28
8. Write a program to read 6 numbers and create a dictionary having keys EVEN and
ODD. Dictionary's value should be stored in list. Your dictionary should be like:
{'EVEN':[8,10,64], 'ODD':[1,5,9]}

9. Write a Python program to print the first 6 terms of a geometric sequence starting
with 2 and having a common ratio of 3. The program should output the following
sequence:
2 6 18 54 162 486
10. Write a program that reads string from user. Your program should create a dictionary
having key as word length and value is count of words of that length. For example, if
user enters 'A fat cat is on the mat'.
Word Word length
A 1
fat 3
cat 3
is 2
on 2
the 3
mat 3
The content of dictionary should be {1:1, 3:4, 2:2}

11. Write a Python program that accepts integers from the user until a zero or a negative
number, display the number of positive values, the minimum value, the maximum
value and the average of all numbers.
12. Write a Python program to sum all the items in a dictionary.
Sample Output
{1 : 23, 2 : 45, 3 : -17, 4 : 87}
Sum all the Items = 138
13. Write a program in C to find the number and sum of all integer between 100 and 200
which are divisible by 9.
14. Write a Python program to Convert two lists into a dictionary
Sample Output
keys = ["One", "Two", "Three", "Four", "Five"]
values = [1, 2, 3, 4, 5]
Convert Two List to Dict = {'One' : 1, 'Two' : 2, 'Three' : 3, 'Four' : 4, 'Five' : 5}

15. Write a Python program to check whether a given number is an Armstrong number
(any number of digits)
16. Write a Python program to count the number of characters (character frequency) in a
string.
Sample String: [Link]'
Expected Result: {'g': 2, 'o': 3, 'l': 1, 'e': 1, '.': 1, 'c': 1, 'm': 1}

17. Write a program in C to find the sum of the series [1-X^2/2!+X^4/4!- .........].
Test Data :
Input the Value of x :2
Input the number of terms : 5
Expected Output :
the sum = -0.415873
Number of terms = 5
value of x = 2.000000
18. Write a Python program to get a string from a given string where all occurrences of its
first char have been changed to '$', except the first char itself.
Sample String: 'restart'
Expected Result: 'resta$t'

19. Write a Python program to check if a string has at least one letter and one number.
20. Write a Python program to print the following pattern:
*
**
***
****
*****

21. Write a Python program to find the least frequent character in a string.
22. Write a Python program to print the following pattern:
1
222
33333
4444444
555555555

23. Write a Python program to check if a string contains any special character.
24. Write a Python program to print the following pattern:
1234
123
12
1
25. Write a program that input a string and ask user to delete a given word from a string.
26. Write a Python program to print the following pattern:

27. Write a Python program that accepts a string from user. Your program should create a
new string by shifting one position to left. For example if the user enters the string
'examination 2021' then new string would be 'xamination 2021e'. a
28. Write a Python program to print the following pattern:

29. Write a Python program to reverse the tuple.


30. Write a Python program to check whether a character is an alphabet, digit or special
character.

31. Write a Python program to check whether an element exists within a tuple.
32. Given an integer, n (1<=n<=100) perform the following conditional actions: (EASY)
a. If n is odd, print Weird
b. If n is even and in the inclusive range of 2 to 5, print Not Weird
c. If n is even and in the inclusive range of 6 to 20, print Weird
d. If n is even and greater than 20, print Not Weird

33. Write a Python program to change the position of every n-th value to the (n+1)th in a
list.
Sample Input: [0,1,2,3,4,5]
Expected Output: [1, 0, 3, 2, 5, 4]
34. Write a program that prompts the user to input a number from 1 to 7. The program
should display the corresponding day for the given number. For example, if the user
types 1, the output should be Sunday. If the user types 7, the output should be
Saturday.

35. Write a Python program that reverses the order of elements in a list (without any in-
built methods).
36. A store offers discounts based on the purchase amount. Write a program to calculate
the discount based on the purchase amount entered by the user.
a. 10% discount for purchases above Rs.1000
b. 5% discount for purchases between Rs. 500 and Rs. 1000
c. No discount for purchases below Rs.500
37. Write a Python program to print all elements in a list those have only single
occurrence.
Example: if contents of list is [7, 5, 5, 1, 6, 7, 8, 7, 6].
Your output should be: 1 8
38. Write a program to check whether the last digit of a number is divisible by 3 or not.

39. Find and display the largest number of a list without using built-in function max().
Your program should ask the user to input values in list from keyboard.
40. A school's grading system determines students' grades based on their marks. Write a
Python program that takes a student's marks as input and displays their corresponding
grade.
90 or above: Grade A, 80-89: Grade B, 70-79: Grade C, 60-69: Grade D, and Below
60: Grade F

41. Write a Python program that rotates the element of a list so that the element at the first
index moves to the second index, the element in the second index moves to the third
index, etc., and the element in the last index moves to the first index.
42. The company decides to grant bonuses to all its employees on Diwali. A 5% bonus on
the salary is offered to male workers, while female workers receive a 10% bonus on
their salary. Write a program to input the employee's salary and gender. If the
employee's salary is less than Rs. 10,000/-, an additional 2% bonus on the salary is
provided. Write a Python program to calculate the total bonus entitled to the employee
and display the final salary that the employee will receive.

43. Write a Python program to remove duplicates from a list.


44. Write a Python program to calculate the root of a Quadratic Equation.

45. Write a Python Program that get two lists as input and check if they have at least one
common member
Sample Output
[1,2,3,4,5]
[5,6,7,8,9]
Lists have at least one common member
46. Write a program that prompts the user to input a year and determine whether the year
is a leap year or not. Leap Years are any year that can be evenly divided by 4. A year
that is evenly divisible by 100 is a leap year only if it is also evenly divisible by 400.
Example :
1992-Leap Year, 2000-Leap Year, 1900-NOT a Leap Year, 1995-NOT a Leap Year

47. Write a Python program to check if the list contains three consecutive common
numbers in Python
Sample Output: [18, 18, 18, 6, 3, 4, 9, 9, 9]
Three Consecutive common numbers = 18, 9
48. Write a program that prompts the user to input number of calls and calculate the
monthly telephone bills as per the following rule:
Minimum Rs. 200 for up to 100 calls.
Plus Rs. 0.60 per call for next 50 calls.
Plus Rs. 0.50 per call for next 50 calls.
Plus Rs. 0.40 per call for any call beyond 200 calls.
49. Write a Python program to count the number of characters (character frequency) in a
string.
Sample String: [Link]'
Expected Result: {'g': 2, 'o': 3, 'l': 1, 'e': 1, '.': 1, 'c': 1, 'm': 1}
50. Write a python program to print the name of a student by getting roll number as input.
(Use dictionaries)

51. Write a Python program to get a string from a given string where all occurrences of its
first char have been changed to '$', except the first char itself.
Sample String: 'restart'
Expected Result: 'resta$t'
52. Write a Python script to generate and print a dictionary that contains a number
(between 1 and n) in the form (x, x*x).

53. Write a Python program to check if a string has at least one letter and one number.
54. Write a Python program to enter names of employees and their salaries as input and
store them in a dictionary. Print the employee name who is paid the highest salary.

55. Write a Python program to find the least frequent character in a string.
56. Write a program to read 6 numbers and create a dictionary having keys EVEN and
ODD. Dictionary's value should be stored in list. Your dictionary should be like:
{'EVEN':[8,10,64], 'ODD':[1,5,9]}

57. Write a Python program to check if a string contains any special character.
58. Write a program that reads string from user. Your program should create a dictionary
having key as word length and value is count of words of that length. For example, if
user enters 'A fat cat is on the mat'.
Word Word length
A 1
fat 3
cat 3
is 2
on 2
the 3
mat 3
The content of dictionary should be {1:1, 3:4, 2:2}

59. Write a program that input a string and ask user to delete a given word from a string.
60. Write a Python program to sum all the items in a dictionary.
Sample Output
{1 : 23, 2 : 45, 3 : -17, 4 : 87}
Sum all the Items = 138

61. Write a Python program to remove all characters from a string except integers.
62. Write a Python program to Convert two lists into a dictionary
Sample Output
keys = ["One", "Two", "Three", "Four", "Five"]
values = [1, 2, 3, 4, 5]
Convert Two List to Dict = {'One' : 1, 'Two' : 2, 'Three' : 3, 'Four' : 4, 'Five' : 5}

63. Write a Python program to count the number of Frequency[char]=


characters (character frequency) in a string.
Sample String: [Link]' [Link](char,0)+1
Expected Result: {'g': 2, 'o': 3, 'l': 1, 'e': 1, '.': 1, 'c': 1, 'm':
1}
64. A school's grading system determines students' grades based on their marks. Write a
Python program that takes a student's marks as input and displays their corresponding
grade. 90 or above: Grade A, 80-89: Grade B, 70-79: Grade C, 60-69: Grade D, and
Below 60: Grade F

65. Write a Python program to get a string from a given string where all occurrences of its
first char have been changed to '$', except the first char itself.
Sample String: 'restart'
Expected Result: 'resta$t'
66. Write a program to check whether the last digit of a number is divisible by 3 or not.

67. Write a Python program to check if a string has at least one letter and one number.
68. The company decides to grant bonuses to all its employees on Diwali. A 5% bonus on
the salary is offered to male workers, while female workers receive a 10% bonus on
their salary. Write a program to input the employee's salary and gender. If the
employee's salary is less than Rs. 10,000/-, an additional 2% bonus on the salary is
provided. Write a Python program to calculate the total bonus entitled to the employee
and display the final salary that the employee will receive.

69. Write a Python program to find the least frequent character in a string.
70. Write a program that prompts the user to input a year and determine whether the year
is a leap year or not. Leap Years are any year that can be evenly divided by 4. A year
that is evenly divisible by 100 is a leap year only if it is also evenly divisible by 400.
Example :
1992-Leap Year, 2000-Leap Year, 1900-NOT a Leap Year, 1995-NOT a Leap Year

71. Write a Python program to check if a string contains any special character.
72. Write a Python program to check whether a character is an alphabet, digit or special
character.

73. Write a program that input a string and ask user to delete a given word from a string.
74. A store offers discounts based on the purchase amount. Write a program to calculate
the discount based on the purchase amount entered by the user.
a. 10% discount for purchases above Rs.1000
b. 5% discount for purchases between Rs. 500 and Rs. 1000
c. No discount for purchases below Rs.500

75. Write a Python program that accepts a string from user. Your program should create a
new string by shifting one position to left. For example if the user enters the string
'examination 2021' then new string would be 'xamination 2021e'.
76. Write a program to check whether the last digit of a number is divisible by 3 or not.

77. Write a Python program to remove all characters from a string except integers.
78. Write a Python program to calculate the root of a Quadratic Equation.

79. Write a Python program to remove the nth index character from a nonempty string.
80. Write a program that prompts the user to input number of calls and calculate the
monthly telephone bills as per the following rule:
Minimum Rs. 200 for up to 100 calls.
Plus Rs. 0.60 per call for next 50 calls.
Plus Rs. 0.50 per call for next 50 calls.
Plus Rs. 0.40 per call for any call beyond 200 calls.

81. Write a Python program that prompts the user to input a number and prints its
multiplication table.
82. Write a Python program to change the position of every n-th value to the (n+1)th in a
list.
Sample Input: [0,1,2,3,4,5] and Expected Output: [1, 0, 3, 2, 5, 4]

83. Write a Python program to print the first 8 terms of an arithmetic progression starting
with 3 and having a common difference of 4. The program should output the
following sequence: 3 7 11 15 19 23 27 31
84. Write a Python program that reverses the order of elements in a list (without any in-
built methods).

85. Write a Python program to check whether an integer is a palindrome.


86. Write a Python program to print all elements in a list those have only single
occurrence.
Example: if contents of list is [7, 5, 5, 1, 6, 7, 8, 7, 6].
Your output should be: 1 8

87. Find and display the largest number of a list without using built-in function max().
Your program should ask the user to input values in list from keyboard.
88. Write a Python program that takes a positive integer N as input and calculates the sum
of the reciprocals of all numbers from 1 up to N. The program should display the final
sum. Output of the program should be like:
Enter a positive integer: 5
The sum of reciprocals from 1 to 5 is: 2.28

89. Write a Python program that rotates the element of a list so that the element at the first
index moves to the second index, the element in the second index moves to the third
index, etc., and the element in the last index moves to the first index.
90. Write a Python program to print the following pattern:
*
**
***
****
*****

91. Write a Python program to remove duplicates from a list.


92. Write a Python program to print the following pattern:
1
222
33333
4444444
555555555
93. Write a Python Program that get two lists as input and check if they have at least one
common member
Sample Output
[1,2,3,4,5]
[5,6,7,8,9]
Lists have at least one common member
94. Write a Python program to print the following pattern:
1234
123
12
1

95. Write a Python program to check if the list contains three consecutive common
numbers in Python
Sample Output
[18, 18, 18, 6, 3, 4, 9, 9, 9]
Three Consecutive common numbers = 18, 9
96. Write a Python program to print the following pattern:

97. Write a Python program that prompts the user to input a number and prints its
multiplication table.
98. Write a Python program to perform basic computations using NumPy functions
(math, trigonometric, logarithms, etc.)

99. Write a Python program to print the first 8 terms of an arithmetic progression starting
with 3 and having a common difference of 4. The program should output the
following sequence:
3 7 11 15 19 23 27 31
100. Write a Python program employing NumPy to convert a list of numeric value
into a one-dimensional NumPy array.

101. Write a Python program to check whether an integer is a palindrome.


102. Write a Python program to convert a list and tuple into arrays using NumPy.

103. Write a Python program that takes a positive integer N as input and calculates
the sum of the reciprocals of all numbers from 1 up to N. The program should display
the final sum. Output of the program should be like:
Enter a positive integer: 5
The sum of reciprocals from 1 to 5 is: 2.28
104. Write a Python program to perform basic data manipulations using Pandas
dataframe.

105. Write a Python program to check if a string has at least one letter and one
number.
106. Write a Python program to convert NumPy array and series into a dataframe.

107. Write a Python program to find the least frequent character in a string.
108. Write a Python program to add, subtract, multiple and divide two Pandas
Series.

109. Write a Python program to check if a string contains any special character.
110. Write a Python program to retrieve and manipulate data using Pandas
dataframe.

111. Write a program that input a string and ask user to delete a given word from a
string.
112. Write a Python program to retrieve and manipulate data using Pandas
dataframe.

113. Write a Python program to check whether a character is an alphabet, digit or


special character.
114. Write a Python program to add, subtract, multiple and divide two Pandas
Series.

115. Given an integer, n (1<=n<=100) perform the following conditional actions:


(EASY)
a. If n is odd, print Weird
b. If n is even and in the inclusive range of 2 to 5, print Not Weird
c. If n is even and in the inclusive range of 6 to 20, print Weird
d. If n is even and greater than 20, print Not Weird
116. Write a Python program to convert NumPy array and series into a dataframe.

117. Write a program that prompts the user to input a number from 1 to 7. The
program should display the corresponding day for the given number. For example, if
the user types 1, the output should be Sunday. If the user types 7, the output should be
Saturday.
118. Write a Python program to perform basic data manipulations using Pandas
dataframe.

119. A store offers discounts based on the purchase amount. Write a program to
calculate the discount based on the purchase amount entered by the user.
a. 10% discount for purchases above Rs.1000
b. 5% discount for purchases between Rs. 500 and Rs. 1000
c. No discount for purchases below Rs.500
120. Write a Python program to convert a list and tuple into arrays using NumPy.

You might also like