0% found this document useful (0 votes)
2 views

Python Coding Questions All Levels

The document contains a series of beginner-level programming questions and their corresponding Python code solutions. Topics include printing numbers, checking even/odd, finding the largest number, swapping values, reversing strings, checking palindromes, calculating factorials, generating Fibonacci series, summing digits, finding GCD, checking prime numbers, counting vowels, creating multiplication tables, printing star patterns, and determining ASCII values. Each question is followed by a simple code snippet demonstrating the solution.

Uploaded by

22ada20
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Coding Questions All Levels

The document contains a series of beginner-level programming questions and their corresponding Python code solutions. Topics include printing numbers, checking even/odd, finding the largest number, swapping values, reversing strings, checking palindromes, calculating factorials, generating Fibonacci series, summing digits, finding GCD, checking prime numbers, counting vowels, creating multiplication tables, printing star patterns, and determining ASCII values. Each question is followed by a simple code snippet demonstrating the solution.

Uploaded by

22ada20
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Beginner Level Questions

Q: Print numbers from 1 to N


n = int(input('Enter N: '))
for i in range(1, n+1):
print(i)

Q: Check if a number is even or odd


n = int(input('Enter number: '))
print('Even' if n % 2 == 0 else 'Odd')

Q: Find the largest of 3 numbers


a, b, c = 5, 10, 3
print('Largest:', max(a, b, c))

Q: Swap two numbers


a, b = 5, 10
a, b = b, a
print(a, b)

Q: Reverse a string
s = input('Enter string: ')
print(s[::-1])

Q: Check if a string is palindrome


s = input('Enter string: ')
print('Palindrome' if s == s[::-1] else 'Not Palindrome')

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: Check if number is prime


n = int(input('Enter number: '))
if n > 1:
for i in range(2, n):
if n % i == 0:
print('Not Prime')
break
else:
print('Prime')
else:
print('Not Prime')

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))

You might also like