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

Python Coding Questions & Answers

The document contains a series of Python coding questions along with their answers. It covers various programming concepts such as loops, conditionals, and functions, demonstrating how to perform tasks like checking even/odd numbers, calculating factorials, and printing patterns. Each question is followed by the expected output, providing a practical reference for Python coding practices.

Uploaded by

aditipatro2008
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 Coding Questions & Answers

The document contains a series of Python coding questions along with their answers. It covers various programming concepts such as loops, conditionals, and functions, demonstrating how to perform tasks like checking even/odd numbers, calculating factorials, and printing patterns. Each question is followed by the expected output, providing a practical reference for Python coding practices.

Uploaded by

aditipatro2008
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

Python Revision – Coding Questions with Answers

Q1. x = 5; y = 2; print(x ** y, x // y, x % y)
Answer: 25 2 1

Q2. for i in range(1, 5): if i == 3: continue print(i, end=' ')


Answer: 1 2 4

Q3. for i in range(2, 6): for j in range(1, i): print(j, end='') print()
Answer: 1 12 123 1234

Q4. x = 10; if x > 0: print('Positive') elif x == 0: print('Zero') else: print('Negative')


Answer: Positive

Q5. a, b, c = 2, 5, 3; if a > b and a > c: print('A') elif b > c: print('B') else: print('C')
Answer: B

Find whether a number is even or odd.


n = 7
if n % 2 == 0:
print('Even')
else:
print('Odd')
Output: Odd

Check if a number is divisible by 5 and 11.


n = 55
if n % 5 == 0 and n % 11 == 0:
print('Divisible')
else:
print('Not Divisible')
Output: Divisible

Print the sum of first N natural numbers.


n = 5
s = n * (n + 1) // 2
print(s)
Output: 15

Display the multiplication table of a given number.


n = 3
for i in range(1, 11):
print(n, 'x', i, '=', n*i)
Output: Table of 3

Find the largest of three numbers.


a, b, c = 10, 20, 15
print(max(a, b, c))
Output: 20

Print all prime numbers between 1 and 50.


for n in range(2, 51):
for i in range(2, n):
if n % i == 0:
break
else:
print(n, end=' ')
Output: 2 3 5 ... 47

Calculate the factorial of a number.


n = 5
fact = 1
for i in range(1, n+1):
fact *= i
print(fact)
Output: 120

Count the number of vowels in a string.


s = 'hello world'
count = 0
for ch in s:
if ch in 'aeiou':
count += 1
print(count)
Output: 3

Display the pattern: * ** *** ****


for i in range(1, 5):
print('*'*i)
Output:
*
**
***
****

Check if a number is palindrome.


n = 121
if str(n) == str(n)[::-1]:
print('Palindrome')
else:
print('Not Palindrome')
Output: Palindrome

You might also like