Python Coding Questions All Levels
Python Coding Questions All Levels
Q: Reverse a string
s = input('Enter string: ')
print(s[::-1])
Q: Factorial of a number
n = int(input('Enter number: '))
fact = 1
for i in range(1, n+1):
fact *= i
print(fact)
Q: Fibonacci series up to N
n = int(input('Enter terms: '))
a, b = 0, 1
for _ in range(n):
print(a, end=' ')
a, b = b, a + b
Q: Sum of digits
n = int(input('Enter number: '))
sum_digits = sum(int(d) for d in str(n))
print(sum_digits)
Q: Find GCD
import math
a, b = 12, 18
print('GCD:', math.gcd(a, b))
Q: Count vowels
s = input('Enter string: ')
vowels = 'aeiouAEIOU'
count = sum(1 for ch in s if ch in vowels)
print(count)
Q: Multiplication table
n = int(input('Enter number: '))
for i in range(1, 11):
print(f'{n} x {i} = {n*i}')
Q: Star pattern
n = 5
for i in range(1, n+1):
print('*' * i)
Q: ASCII value
ch = input('Enter character: ')
print('ASCII:', ord(ch))