0% found this document useful (0 votes)
3 views2 pages

Python Practice Questions and Solutions

Uploaded by

ddhiraj283737
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)
3 views2 pages

Python Practice Questions and Solutions

Uploaded by

ddhiraj283737
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

Sample Questions Patterns for practices

(These questions will not be part of questions paper.)


1. Write output for below code

fruits = ["apple", "banana", "cherry"]


for i in range(len(fruits)):
print(fruits[i])
Output:
1
4
9
16
2. Write output of the below code:
count = 1
while count < 4:
print("Count:", count)
count += 1

Output:
Count: 1
Count: 2
Count: 3

3. Rewrite the program after removing syntactical error and underline the corrections
i = 10
while i > 0
Print(i)
i = i+ 1

Answer:
i = 10
while i > 0 :
print(i)
i = i+ 1

4. Write a programs to print first N natural numbers where N will be given by user.

Answer:

n = int(input("Enter N: "))
for i in range(1, 2 * n, 2):
print(i, end=" ")
5. Write a program to check whether twor string are same or not?

Answer

s1 = "Hello"
s2 = "Hello"
if s1 == s2:
print("Strings are the same")
else:
print("Strings are different")

6. Count the number of occurrences of 1 in the list L = [1,2,3,4,2,3,4,1,2,3,1,4,3]

Answer
L = [1,2,3,4,2,3,4,1,2,3,1,4,3]
cnt = 0
for x in L:
if x == 1:
cnt = cnt+ 1
print(cnt)

7. Write a program to increase by 1 to all the number multiples of 5 in the list below
L = [23,2,45,65,12,20,35,3,70]

Answer

L = [23,2,45,65,12,20,35,3,70]
for i in range(len(L)):
if L[i] % 5 == 0:
L[i] = L[i] + 1
print(L)

8. Input an number and check whether it is Positive, Negative, or Zero?


Answer
number = int(input("Enter a number: "))
if number > 0:
print("Positive number")
elif number < 0:
print("Negative number")
else:
print("Zero")

You might also like