0% found this document useful (0 votes)
10 views3 pages

Sample Python Programs

The document provides a list of sample Python programs for practice, including tasks such as checking for prime numbers, determining even or odd numbers, and calculating factorials. It also includes examples of output-based questions with explanations. The focus is on basic programming concepts and operations in Python.

Uploaded by

wwwanuj7065
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)
10 views3 pages

Sample Python Programs

The document provides a list of sample Python programs for practice, including tasks such as checking for prime numbers, determining even or odd numbers, and calculating factorials. It also includes examples of output-based questions with explanations. The focus is on basic programming concepts and operations in Python.

Uploaded by

wwwanuj7065
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

Sample python program for practice

[Link] program for prime number


2. Program for checking of even odd
3. Program for checking Armstrong
number
4. Program for checking biggest
number in given two numbers
[Link] the factorial of a given
number
6. calculate the average of given two
numbers.
7. add or substract any element in
the given list
8. Practice list slicing.
9. practice some output based
question from book.

Examples
1. Question
x = 5
y = 2
print(x + y * 3)

Answer:

11

Explanation:
Multiplication happens first → 2 * 3 = 6, then 5 + 6 = 11.

2. Question
a = "Hello"
b = "World"
print(a + " " + b)

Answer:

Hello World

Explanation:
Strings are concatenated using +.

3. Question
num = 10
if num > 5:
print("A")
else:
print("B")

Answer:

Explanation:
Since 10 > 5, the if block executes.

4. Question
for i in range(3):
print(i, end=" ")
Answer:

0 1 2

Explanation:
range(3) generates numbers 0, 1, 2.

5. Question
x = [1, 2, 3]
print(len(x))

Answer:

Explanation:
The list contains 3 elements.

You might also like