Practice what you learned and become a better coder!
Start with an easy challenge and work your way up.
Write a Python program that prints "Hello Python!".
Write a program that prints the number 10.
Write a program that prints the result of 5 + 7.
Write a Python program that prints your name. For example, print "Alex".
Write a program that prints "I am learning Python!" and "Python is fun!".
Write a program that prints the result of 20 - 8.
Write a program that prints the text "5 x 4 =" followed by the result of 5 * 4 on the same line.
Create a variable called name and store "Alex" in it.
Create a variable called age and store 12 in it.
Create a variable called score with the value 10, then change it to 50.
Create variables called name and age. Store "Sam" in name and 11 in age.
Create two variables called a and b with values 10 and 5. Print their total.
Create a variable called score with the value 10. Add 5 to it using score = score + 5, then print score.
Create a variable called age and store the number 12 in it.
Create a variable called name and store "Alex" in it.
Create a variable called is_student and store True in it.
Create a variable called height and store the decimal number 4.5.
Create a variable called score with the value 100 and use type() to check its data type.
Convert the string "25" into an integer and print the result.
Print the result of 20 + 10.
Print whether 20 is greater than 10.
Print the remainder when 10 is divided by 3.
Create two variables called price and quantity with values 10 and 3. Print their product.
Create a variable called lives with the value 3. Use += to add 2 more lives, then print lives.
Print the result of 3 to the power of 2.
There are 17 sweets to share equally between 5 friends. Print how many sweets each friend gets, then print how many sweets are left over.
Create a variable called age with the value 11 and a variable called height with the value 140. Print whether age is at least 10 and height is at least 130.
Create two variables: one with "Ice" and one with "Cream". Join them with a space in between and print "Ice Cream".
Make a variable called name with your name in it. Use an f-string to print "Hello, <name>!". For example, "Hello, Alex!".
Print the number of characters in the string "butterfly".
Store the text "we won the game" in a variable, then print it in all capital letters.
Store the word "elephant" in a variable. Print its first letter, then its last letter, then the first three letters.
Store "My dog is sleepy" in a variable. Print the sentence with "dog" replaced by "cat", then print whether the word "sleepy" is in the sentence.
Ask the user for their name using input(), then print "Nice to meet you, <name>!".
Ask the user for their favourite animal and print "<animal> is a great choice!".
Ask the user for a whole number, turn it into a number with int(), and print the number multiplied by 2.
Ask the user for two whole numbers, one at a time. Add them together and print the total.
Ask the user how much money they save each week (it can be a decimal like 2.5). Print how much they will have after 4 weeks.
Ask the user for their age and for the current year. Print the year they were probably born in.
If age is greater than or equal to 10, print You can play.
If score is 50 or more, print Passed. Otherwise print Try again.
Check whether a number is greater than 10.
Create a variable called password with the value "python123". If password is equal to "python123", print Access granted. Otherwise print Access denied.
Create a variable called number with the value 7. Print Even if the number is even, otherwise print Odd.
Create a variable called day with the value "Saturday". If day is "Saturday" or "Sunday", print Weekend! Otherwise print School day.
Create a variable called score with the value 85. Print A for 90 or more, B for 75 or more, C for 60 or more, and D for anything lower.
Use a for loop to print numbers from 0 to 4.
Use a loop to print "Python is fun!" three times.
Use a while loop to print 1, 2, and 3.
Use a for loop to print the even numbers 2, 4, 6, 8, and 10.
Create a list called friends with "Mia", "Leo" and "Zara". Use a for loop to print Hi followed by each name.
Use a for loop to count down from 10 to 1, then print Blast off!
Use a loop to add up all the numbers from 1 to 10, then print the total.
Write a loop that prints the numbers from 10 down to 1, but stops with break when it reaches 6 (so 6 is not printed).
Loop through the numbers 1 to 10 and use continue to skip odd numbers, so only even numbers are printed.
Use a for loop to print each letter of the word "ROCKET" on its own line.
Use a running total to add up all the numbers from 1 to 100 and print the answer.
Use nested loops to print a triangle of stars with 5 rows. The first row has 1 star and the last row has 5 stars.
Use nested loops to print the 1, 2, and 3 times tables from 1 to 3. Each line should look like 2 x 3 = 6.
Create a list containing "Apple", "Banana" and "Mango".
Create a list with "Apple", "Banana" and "Mango", then print the first item.
Create a list with "Apple" and "Banana", then add "Mango".
Create a list called animals with "cat", "dog", "rabbit" and "hamster". Print how many items are in the list.
Create a list called colors with "red", "green" and "blue". Remove "green", then print the list.
Create a list called fruits with "Apple", "Banana" and "Mango". Print whether "Banana" is in the list.
Create a list called toys with "ball", "kite" and "robot". Use a for loop to print each toy on its own line.
Create a list called scores with 45, 90, 12 and 78. Sort the list from smallest to largest, then print it.
Create a list called numbers with 10, 20, 30, 40 and 50. Use slicing to print only the first three items.
Create a tuple called colours with "red", "yellow", and "blue". Print the whole tuple, then print the second colour.
Create a tuple pet = ("Rex", "dog", 4). Unpack it into three variables name, kind, and age, then print "Rex is a dog and is 4 years old".
Create a set from the numbers 5, 2, 5, 8, 2, 8, 8. Print how many items are in the set.
Start with a set of stickers {"star", "moon"}. Add "sun", add "star" again, then print the sorted set and whether "moon" is in it.
You have a list of names: ["Ava", "Ben", "Ava", "Cal", "Ben"]. Remove the duplicates using a set and print the unique names in sorted order.
Sam likes {"tag", "chess", "football"} and Priya likes {"chess", "football", "tennis"}. Print the games they both like, in sorted order.
Make a dictionary called favourites with the keys "food", "colour", and "animal" and your own values. Print the whole dictionary.
Create capitals = {"France": "Paris", "Japan": "Tokyo", "Egypt": "Cairo"}. Print the capital of Japan.
Create hero = {"name": "Nova", "health": 100}. Change health to 80, add a new key "power" with the value "flying", then print hero.
Create snacks = {"chips": 3, "cookies": 5}. Use get() to print how many cookies there are, then use get() with a backup value of 0 to print how many cakes there are.
Create prices = {"apple": 2, "banana": 1, "cherry": 5}. Loop through it with items() and print each line like "apple costs 2".
Create scores = {"Ana": 8, "Ben": 6, "Cleo": 9}. Use a loop to add up all the scores and print the total.
Create a function called greet that prints Hello.
Create a function called greet that accepts a name and prints Hello followed by the name.
Create a function called add that accepts two numbers and returns their sum.
Create a function called say_hi that prints Hi! Then call the function two times.
Create a function called square that returns a number multiplied by itself. Print the result of square(4).
Create a function called greet with a parameter name that has the default value "friend". It should print Hello followed by the name. Call greet() without any value.
Create a function called is_even that returns True if a number is even and False if it is not. Print the result of is_even(10).
Create a function called area that returns width * height. Then create a function called show_area that calls area() and prints "The area is" followed by the answer. Call show_area(3, 4).
Import the math module and print the square root of 49.
Import the random module and print a random number from 1 to 6, just like rolling a die.
Make a list of snacks: "apple", "popcorn", "cookie". Use random.choice() to print one random snack.
A circle has a radius of 3. Use math.pi to find its area (pi x radius x radius) and print it rounded to 2 decimal places.
Make a list of players: "Ava", "Leo", "Zoe", "Sam". Shuffle the list with random.shuffle() and print the new order.
Ask the user to type a yes-or-no question with input(). Then print a random answer from the list "Yes!", "No way!", "Maybe...", "Ask again later".
This code has a SyntaxError: print("Hello World!" . Fix it so it prints Hello World!
This code gives a NameError: name = "Mia" print(nmae) Fix the typo so it prints Mia.
This code gives a TypeError: age = 10 print("I am " + age + " years old") Fix it so it prints I am 10 years old
Use try and except to divide 10 by 0. If a ZeroDivisionError happens, print "You can't divide by zero!"
Ask the user for their age with input(). Use try and except ValueError so that if they type something that is not a number, the program prints "Please type a number!" instead of crashing. If it is a number, print their age next year.
Try to turn the text "abc" into a number with int(). Catch the ValueError and print "That is not a number!". Add a finally part that prints "All done!".
Import turtle, create a turtle, and make it move forward 150 steps.
Use a for loop to make the turtle draw a square with sides of 80 steps.
Use a for loop to draw a triangle with sides of 100 steps.
Draw a gold 5-pointed star with sides of 120 steps.
Draw a hexagon (6 sides) filled with your favorite color. Make the pen thicker with pensize().
Write a function called draw_triangle(size) that draws a triangle. Call it three times with sizes 50, 100, and 150.
Create a class called Cat with an attribute sound = "Meow!". Make a Cat object and print its sound.
Create a class called Car with an __init__ method that takes color and brand. Make a red Toyota car and print its color and brand on separate lines.
Create a class Robot with a name attribute and a method greet() that prints "Beep boop! I am" followed by the name. Make a robot named Robo and call greet().
Create a class Pet with name and animal attributes and a method introduce() that prints the name, "is a", and the animal. Make three pets: Max the dog, Bella the cat, and Nemo the fish, and call introduce() for each.
Create a class Player with a name and a score that starts at 0. Add a method add_points(amount) that adds to the score and prints the name, "has", the score, and "points". Make a player named Zara and add 10 points, then 25 points.
Create a class Animal with a name and a method eat() that prints the name and "is eating". Then create a class Dog that inherits from Animal and adds a method bark() that prints "Woof!". Make a Dog named Rocky and call eat() and bark().