FIVE BEGINNER PYTHON PROJECTS
I decided to write this because I see a bunch of beginners asking what they should do, so here are five really simple and fun projects!
1. Adventure Story
The first thing you need with an adventure story is a great storyline, something that is exciting and fun. The idea is, that at each pivotal point in the story, you give the player the opportunity to make a choice.
First things first, let’s import the stuff that we need, like this:
import os #very useful for clearing the screen import random
Now, we need some variables to hold some of the player data.
name = input(“Name Please: “) #We’ll use this to get the name from the user nickname = input(“Nickname: “)
Ok, now we have the player’s name and nickname, let’s welcome them to the game
print(“Hello and welcome “ + name)
Now for the story. The most important part of all stories is the introduction, so let’s print our introduction
print(“Long ago, there was a magical meal known as Summuh and Spich Atip”) #We can drop a line by making a new print statement, or we can use the escape code \n print(“It was said that this meal had the power to save lives, restore peace, and stop evil\nBecuase it was so powerful, it was hidden away on a mountain that could not be climbed\nBut it’s power brought unwanted attention, and a great war broke out.\nFinally, the leaders of the good side chose a single hero to go and find the Summah and Spich Atip, that hero was “ + name + “\n so ” + nickname + ‘ headed out to find this great power, and stop the war…’)
Now, we’ll give the player their first choice
print(“After hiking through the wastelands for a long time, you come to a massive ravine, there is only a single way across\nA rickety old bridge, taking that could be very dangerous, but… maybe you could jump across?”) choice1 = input(“ Take the bridge  Try and jump over”) #Now we check to see what the player chose If choice1 == ‘1’: print(“You slowly walk across the bride, it creakes ominously, then suddenly breaks! You flail through the air before hitting the ground a thousand feet below. Judging by the fact that you hit the ground with the equivalent force of being hit by a cement truck moving at 125 miles an hour, you are dead…”) #The player lost, so now we’ll boot them out of the program with the exit command exit() #Then we check to see if they made the other choice, we can do with with else if, written as elif elif choice1 == ‘2’: print(“You make the jump! You see a feather hit the bridge, the weight breakes it and sends it to the bottom of the ravine\nGood thing you didn’t use that bridge.”) #Now we can continue the story print(“A few more hours of travel and you come to the unclimbable mountain.”) choice2 == input(“ Give up  Try and climb the mountain”) if choice2 == ‘1’: print(“You gave up and lost…”) #now we exit them again exit() elif choice2 == ‘1’: print(“you continue up the mountain. Climbing is hard, but finally you reach the top.\nTo your surprise there is a man standing at the top of the mountain, he is very old.”) print(“Old Man: Hey “ + nickname) print(“You: How do you know my name!?!”) print(“Old Man: Because you have a name tag on…”) print(“You: Oh, well, were is the Summuh and Spich Atip?”) print(“Old Man: Summuh and Spich Atip? You must mean the Pita Chips and Hummus”) print(“You: Pita…chips…humus, what power do those have?”) print(“Old Man: Pretty simple kid, their organic…”) #Now let’s clear the screen os.system(‘clear’) print(“YOU WON!!!”)
There you have it, a pretty simple choose your own ending story. You can make it as complex or uncomplex as you like.
2. TEXT ENCODER
Ever make secret messages as a kid? I used to. Anyways, here’s the way you can make a program to encode messages! It’s pretty simple. First things first, let’s get the message the user wants to encode, we’ll use input() for that:
message = input(“Message you would like encoded: “)
Now we need to split that string into a list of characters, this part is a bit more complicated.
#We’ll make a function, so we can use it later def split(x): return (char for char in x) #now we’ll call this function with our text L_message = message.lower() #This way we can lower any of their input encode = split(l_message)
Now we need to convert the characters into code, well do this with a for loop:
out =  for x in encode: if x == ‘a’: out.append(‘1’) elif x == ‘b’: out.append(‘2’) #And we’ll continue on though this with each letter of the alphabet
Once we’ve encoded the text, we’ll print it back for the user
x = ‘ ‘.join(out) #this will turn out into a string that we can print print(x)
And if you want to decode something, it is this same process but in reverse!
3. Guess my Number
Number guessing games are fun and pretty simple, all you need are a few loops. To start, we need to import random.
That is pretty simple. Now we’ll make a list with the numbers were want available for the game
num_list = [1,2,3,4,5,6,7,8,9,10]
Next, we get a random number from the list
num = random.choice(num_list)
Now, we need to ask the user for input, we’ll to this with a while loop
while True: # We could use guess = input(“What do you think my number is? “), but that would produce a string, and numbers are integers, so we’ll convert the input into an integer guess = int(input(“What do you think my number is? “)) #Next, we’ll check if that number is equal to the number we picked if guess == num: break #this will remove us from the loop, so we can display the win message else: print(“Nope, that isn’t it”) #outside our loop, we’ll have the win message that is displayed if the player gets the correct number. print(“You won!”)
Have fun with this!
Here is a more advanced project, but still pretty easy. This will be using a txt file to save some notes. The first thing we need to do is to create a txt file in your repl, name it ‘notes.txt’
Now, to open a file in python we use open(‘filename’, type) The type can be ‘r’ for read, or ‘w’ for write. There is another option, but we won’t be using that here. Now, the first thing we are going to do is get what the user would like to save:
message = input(“What would you like to save?”)
Now we’ll open our file and save that text
o = open(‘notes.txt’, ‘w’) o.write(message) #this next part is very important, you need to always remember to close your file or what you wrote to it won’t be saved o.close()
There we go, now the information is in the file. Next, we’ll retrieve it
read = open(‘notes.txt’, ‘r’) out = read.read() # now we need to close the file read.close() # and now print what we read print(out)
There we go, that’s how you can open files and close files with python
5. Random Dare Generator
Who doesn’t love a good dare? Here is a program that can generate random dares. The first thing we’ll need to do is as always, import random. Then we’ll make some lists of dares
import random list1 = [‘jump on’, ‘sit on’, ‘rick roll on’, ‘stop on’, ‘swing on’] list2 = [‘your cat’, ‘your neighbor’, ‘a dog’, ‘a tree’, ‘a house’] list3 = [‘your mom’, ‘your best friend’, ‘your dad’, ‘your teacher’] #now we’ll generate a dare while True: if input() == ‘’: #this will trigger if they hit enter print(“I dare you to “ + random.choice(list1) + ‘ ‘ + random.choice(list2) + ‘ in front of ‘ + random.choice(list3)
That’s it, a quick and simple dare generator.
You can get all the code below, and if you have any problems, just let me know so I can fix them.