Hey everyone!
Are you looking to sharpen your Python skills and track your progress?
Practising coding challenges is one of the best ways to achieve that!
This post compiled a set of beginner-level Python practice questions for you to practice and enhance your coding abilities.
Ready to dive in and see how much you’ve learned?
Let’s get started!
Basics Python Questions
Here are some beginner-friendly Python coding questions, starting from “Hello, World!” and gradually increasing in complexity:
✨ Write a Python program to print “Hello World”.
print("Hello World")
✨ Write a Python program that prompts the user to enter two numbers and then prints their sum.
num1=int(input("Enter the first number"))
num2=int(input("Enter the second Number"))
sum=num1+num2
print("The sum is:", sum)
✨ Write a Python program that prompts the user to enter first and last names and then concatenate them as full names.
first_name=input("Enter the first name ")
last_name=input("Enter the last name ")
full_name=first_name+" "+last_name
print("The full name is:", full_name)
✨ Write a Python program that prompts the user to enter the radius of a circle and then calculates and prints the area of the circle
Note: area of circle=π×r^2
import math
radius = float(input("Enter the radius of the circle: "))
area = math.pi * (radius ** 2)
print("The area of the circle is:", area)
✨ Write a Python program to swap two numbers.
a = int(input("Enter integer a: "))
b= int(input("Enter integer b: "))
a,b=b,a
print("a: ",a)
print("b: ",b)
✨ Write a Python program to find even or odd number
number = int(input("Enter an integer: "))
if number % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")
✨ Write a Python program that prompts the user to enter the age to check whether the user is eligible to vote or not.
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
✨ Write a program that performs basic arithmetic operations (+, -, *, /,%) based on user input.
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operation = input("Enter operation (+, -, *, /,%): ")
if operation == '+':
result = num1 + num2
elif operation == '-':
result = num1 - num2
elif operation == '*':
result = num1 * num2
elif operation == '/':
result = num1 / num2
elif operation == '%':
result = num1 % num2
else:
result = "Invalid operation"
print("The result is:", result)
✨ Write a program that takes three numbers from the user and prints the largest one.
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if num1 >= num2 and num1 >= num3:
print("The largest number is:", num1)
elif num2 >= num1 and num2 >= num3:
print("The largest number is:", num2)
else:
print("The largest number is:", num3)
✨ Write a Python program that checks if a number entered by the user is positive or negative.
number = float(input("Enter a number: "))
if number > 0:
print("The number is positive.")
elif number < 0:
print("The number is negative.")
else:
print("The number is zero.")
✨ Write a Python program that counts the number of characters in a string entered by the user.
string = input("Enter a string: ")
length = len(string)
print("The number of characters in the string is:", length)
✨ Write a Python program to print natural numbers from 1 to 10.
for i in range(1,11):
print(i)
✨ Write a Python program to print even numbers between 0 to 20.
for i in range(0,21,2):
print(i)
✨ Write a program that prints the first 10 numbers in the Fibonacci sequence
# Initialize the first two numbers of the Fibonacci sequence
a, b = 0, 1
for i in range(10):
print(a, end=" ")
a, b = b, a + b
✨ Write a program that takes a string from the user and prints it in reverse.
string = input("Enter a string: ")
reversed_string = string[::-1]
print("The reversed string is:", reversed_string)
✨ Write a Python program that prompts the user to enter a single letter and checks whether it is a vowel or a consonant.
letter = input("Enter a letter: ").lower()
if letter in 'aeiou':
print("The letter is a vowel.")
else:
print("The letter is a consonant.")
✨ Write a Python program that checks if a word entered by the user is a palindrome (a word that reads the same forward and backward).
word = input("Enter a word: ")
if word == word[::-1]:
print("The word is a palindrome.")
else:
print("The word is not a palindrome.")
✨ Write a program that takes a string from the user and counts the number of vowels in it.
string = input("Enter a string: ")
vowel_count = 0
for char in string.lower():
if char in "aeiou":
vowel_count += 1
print("The number of vowels in the string is:", vowel_count)
✨ Write a Python Program to find the even numbers from the list.
list1=[18,20,39,47,53,62,84]
for i in list1:
if i%2==0:
print(i)
✨ Write a program to remove the duplicates from the list.
list_value=[18,20,39,47,53,62,84,20,47]
unique_elements =set(list_value)
unq_list=list(unique_elements)
print(unq_list)
✨ Write a program to show a two-dimensional matrix
matrix=[[1,2,3],[4,5,6],[7,8,9]]
for row in matrix:
for col in row:
print(col, end=" ")
print()
Conclusion
I know this isn’t enough to make you a pro in Python.
However, if you are a complete beginner in programming, I’m confident that these exercises will help you understand programming better.
Try to solve them on your own first, but if you need help, feel free to refer to the solutions.
If you want to learn more, you can visit websites like w3schools, GeeksforGeeks, and many others.
Finally, I want to give you one coding exercise to try. I hope you’ll like it.
Write a Python program to implement the Caesar Cipher, a basic encryption technique where each letter in the plaintext is shifted a certain number of places down or up the alphabet.
For more details and a deeper understanding of “what is required to do?” you can refer to the provided link.
Leave a Reply