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

All Python Question

Uploaded by

rekharathod2882
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views10 pages

All Python Question

Uploaded by

rekharathod2882
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

1.

Take a number from the user and check if the number is positive or
not?
2. Write a program to check the leap year or not
3. Write a program to find the lowest number out of two numbers
entered by the user?
4. Write a program to check whether a person is a senior citizen or not?
5. Write a program to check whether a number is divisible by 7 or not?
6. Write a program to check whether a person is eligible to vote or not?
7. Write a program to display “Hello” if a number entered by the user is
divisible by 5?
8. Write a program to accept a number from 1 to 7 and display the name
of the day like 1 for Sunday, 2 for Monday.
9. Write a Python function that checks if a given string is a palindrome
10. Create a program that determines if a given number is a prime
number or not?
11. Write a program to take “gender” as input from the user. If the user
is male, give the message: Good Morning Sir. If the user is female,
give the message: Good Morning Ma’am.
12. Write a program to take input max age & current age from the user.
If the current age is less than or equal to max age, show the message
“You are w elcome”.
13. Write a program to create a calculator for +,-,*, / & % using if
statements. Take the following input: a) First number b) Second
number c) Operation (+, -, *, /, %) Compute & show the calculated
result to the user.
14. . Write a program that takes input user’s score, if it’s greater than
50, say “You are passed”. Otherwise, show “Try again!”.
15. Write a Python program to check whether an alphabet is a vowel
or consonant.
16. Print the first 10 natural numbers using a loop.
17. Python program to count the number of even and odd numbers
from a series of numbers.
18. Python program to print all the even numbers within the given
range.
19. Calculate factorial of a number using a for loop:
20. Write a program to find the factorial of a number.
21. Write a program to display the sum of odd and even numbers that
fall between 12 and 37.
22. Write a program to calculate the power (x=2,n=5)
2**5=32
23. Write a program that displays all leap years from 1900-2101.
24. Write a program to sum of squares of even numbers.
25. Write a program to sum of squares of odd numbers.
26. Write a program to use a for loop to calculate the average of first
n natural numbers.
27. Write a program to print squares of all odd numbers of tuples.
28. Write a program to store the sum of the sub tuples of given tuple
into new tuples
for ex:- T1=((1,2,3),(45,23),(98,34,67))

Output:-
T2=(6,68,177)

29. Write a program to store the maximum value of the sub tuples of
given tuple into new tuples
for ex:- T1=((1,2,3),(45,23),(9,4,7))
Output:-
T2=(3,45,9)
30. Write a program to display names starting from vowel from the
given tuple
for ex:- T1=(“Amit”,”Ram ”,”Esha”,”harry”)
Output:-
Amit
Esha

31. Write a Python program to create a tuple.


32. Write a Python program to create a tuple with different data
types.
33. Write a Python program to create a tuple of numbers and print
one item.
34. Write a Python program to get the 4th element from the last
element of a tuple.
tuplex = (4, 6, 2, 8, 3, 1)
Output:
(4, 6, 2, 8, 3, 1)
(4, 6, 2, 8, 3, 1, 9)
35. Write a Python program to convert a list to a tuple
listx = [5, 10, 7, 4, 15, 3]
Output:
(5, 10, 7, 4, 15, 3)
.
Nested list .
Given:
36. L1 = ['a', 'b', ['cc', 'dd', ['eee', 'fff']], 'g', 'h']

Output:
['cc', 'dd', ['eee', 'fff']]
['eee', 'fff']
eee

37. L2 = ['a', ['bb', 'cc'], 'd']


Output: ['a', ['bb', 0], 'd']

38. 7.Write a Python program to access the 2nd position value in


tuple(use indexing)
x = (5, 10, 7, 4, 15, 3)
Output:
10
5, 10, 7
39. 8.Write a Python program to access the last position value in
tuple(using negative indexing)

t = (5, 10, 7, 4, 15, 3)


Output:
3,7
40. Write a program to print the common element from the given tuple
for ex:- T1=(1,2,3,4,5,6)
T2=(3,68,6,177)
Output:-
(3,6)

41. Write a program to accept a number from the user and create a
tuple containing all the factors of the number and also print the sum
of the factors.
Sample Output:-
Enter any number:-9
Tuple is (1,3,9)
42. Write a program to print “hello world” using a function?

43. A simple function ‘fun’ that takes an argument name and prints a
greeting message using that name.
44. Write a function add_numbers that takes two arguments, adds
them together, and prints the result

45. Write a function ‘Subtract_numbers’ that takes two arguments,


subtract them together, and prints the result

46. Write a function to add AND subtract two matrices element-


wise.
matrix1 = [ [1, 2, 3],
[4, 5, 6],
[7, 8, 9] ]
matrix2 = [ [9, 8, 7],
[6, 5, 4],
[3, 2, 1] ]
47. Multiply two matrices using matrix multiplication rule .
matrix1 = [ [2, 2, 3],
[4, 2, 6],
[2, 2, 2] ]
matrix2 = [ [9, 2, 2],
[6, 2, 4],
[2, 2, 2] ]
48. Write a function to the sum of the elements in a given row AND
column of the matrices.
matrix1 = [ [7, 2, 3],
[4, 8, 6],
[7, 8, 8] ]
matrix2 = [ [9, 8, 7],
[6, 12, 4],
[3, 2, 11] ]

49. Write a function to find the maximum & minimum element in a


matrix.
matrix1 = [ [1, 22, 3],
[42, 5, 6],
[7, 8, 89] ]

50. Write a function to count the number of zero elements in the


matrix.
a. matrix1 = [ [0, 22, 3],
b. [42, 5, 6],
c. [7, 0, 0] ]

51. Write a function to search for an element taken by the user in a


matrix and return its position.

52. Write a function to find the maximum AND minimum element


in each row & column.
53. Write a function to swap two columns in a matrix.
54. Create a 2D NumPy array with shape (2, 3) filled with zeros.
55. Add two NumPy arrays: array1 = np.array([1, 2, 3]) and array2 =
np.array([4, 5, 6]).
56. Create a 3x3 array filled with ones.
57. Find the mean of the array np.array([10, 20, 30, 40]).
58. Concatenate the arrays np.array([1, 2, 3]) and np.array([4, 5, 6]).
59. Calculate the standard deviation of the array np.array([1, 2, 3, 4,
5]).
60. Transpose the array np.array([[1, 2], [3, 4]])
61. Write a program to create a simple line plot and add a title to a
plot?
62. Write a program to create a scatter plot?
63. Write a program to change the color of a line plot?
64. Write a program to create a bar plot?
65. How do you create a histogram and add gridlines to a plot?
66. Write a program to add a legend to a plot?
67. Write a program to create multiple subplots?
68. Write a program to create a pie chart?
69. Write a program to change the size of a plot?
70. How do you add text to a specific point on a plot?
71. How do you create a box plot?
72. Write a program to add a colorbar to a plot?
a. Write a program to load the dataset students.csv into a Pandas
DataFrame and display the first 5 rows.
73. Write a program to extract the Name and Marks columns from
the DataFrame.
74. Write a program to find all students who scored more than 80
marks.
75. Write a program to check if there are any missing values in the
dataset. If yes, display the rows with missing values.
76. Write a program to group the students by City and calculate the
average Marks for each city.
77. Write a program to fill any missing values in the Marks column
with the average marks of all students.
78. Write a program to check for duplicate rows in the dataset and
remove them if any exist.
79. Write a program to find all male students who are older than 18
and scored more than 70 marks.
80. Write a program to use Pandas plotting capabilities to create a
bar chart showing the average marks for each City.
81. Calculate the following for the Marks column:
a. Mean
b. Median
c. Standard deviation
82. Write a python program to convert all letters of string in
uppercase.
83. Write a python program to perform following task
a. “Hello, my friends, I am Jeck”
b. Replace Jeck with Tiya
84. Write a python program to check the index of a particular
character.
85. Write a python program to create a substring from a string.
86. Write a python program to demonstrate the use of join function.
87. Write a python program which takes two strings as input and
prints a new string made by taking the four characters from
the first string and the last four characters from the second string
and concatenating them.
88. Write a python program which takes two strings as input from
the user to count the number of vowels and consonants in a
string.
89. Write a python program to demonstrate the use of membership
operators. name="Marium"
90. Write a python program to demonstrate the use of the repetition
operator of String. str1="2"
91. Write a python program for following task:
Take a string from the user as input and check whether it is starting with
the letter “a” or not. If it is starting with “a” prompt user that is
the first name of the list, and if it is not starting with “a” prompt
user that string is not starting with letter “a”.
92. Creating a Class and Object

Problem:
Define a Person class with the attributes name and age. Create
an object of this class and print out the details.

93. Method to Calculate Area of Rectangle

Problem:
Define a Rectangle class with the attributes length and width. Add
a method to calculate the area of the rectangle.

94. Simple Method Inside Class

Problem:
Create a class Car that has a method start() which prints "The car
has started." Create an object of the Car class and call the start()
method.

95. How do you create a simple Gradio interface for a function?

Problem:
Create a simple Gradio interface for a function that adds two
numbers.

96. How do you display text output using Gradio?

Problem:
Create a Gradio interface that takes a text input and returns the
text in uppercase.

97. How do you create an interface for an image classification


function?
Problem:
Create a Gradio interface for an image classification function that
takes an image and returns a label.

98. How do you create a Gradio interface for a machine


learning model?

Problem:
Create a Gradio interface for a machine learning model, for
example, a simple function that classifies a number as "even" or
"odd".

99. How do you customize the Gradio interface theme and


title?

Problem:
Create a Gradio interface with a custom title and theme.

100.How do you use a Gradio interface with multiple outputs?

Problem:
Create a Gradio interface that takes a number as input and
returns both its square and cube.

101. How do you create a Gradio interface for a function with


two different input types?

Problem:
Create a Gradio interface that takes both a number and a text
input, and returns a message that combines both inputs.

You might also like