Module 7 Instrstructions
Module 7 Instrstructions
NOTE – Make sure you right click and open each link in its own tab.
Requirements:
The lab requires you to create three Python programs. I believe it is best if you create these programs in
an editing tool. This makes sure you can save the programs to your computer. Below is a list of editors I
recommend:
• For Windows users, I recommend downloading Notepad++. NOTE – Please make sure Python is
chosen as the Language: https://www.screencast.com/t/VDCgB0fA
• For MAC Users, review two links below:
o Configure TextEdit on Macs
o Brackets (Mac Only)
After you have created your Python files with the text editor, you will copy and paste your code into an
online complier named OnlineGDB. Please go to https://www.onlinegdb.com/ and then watch the
following video carefully.
• https://www.screencast.com/t/enan8idPKYsj
You will create three programs in this lab. The lab instructions provide helpful guidelines, but not
specific steps. Work carefully; programming requires precision, so type program statements exactly as
they are printed. If you encounter syntax or runtime errors, look carefully at your code to find the
errors.
You will use the Program Answer Sheet to add your screen shots and answer the questions to each of
the programs.
Program 1: Wacky Word Game Background
This program introduces you to the use of variables, strings and input. The program produces a game
that prompts a player for a list of words and then asks the player to use them in a story or poem. The
output generates a nonsensical or comical story.
1. Enter the following program in your text editor and save the file as game.py. Remember that
the code below may need to be fixed a bit for it to run correctly in the OnlineGDB editor:
2. Please copy and paste your code into the OnlineGDB complier into the main.py area and run it.
3. Please take a screen shot of your code and the output from the OnlineGDB site and label it
Figure 1.
Answer the following questions about this program on the Answer Sheet:
• Why did you have to use an underscore between the words first and name?
• Why does each variable have to have a unique name?
• What is the purpose of using the print("") command?
• Why does each line of code need to be on their own line?
• Why is it important to use comments in your programming code?
Program 2: Build Your Own Calculator Background
This program uses requests two numbers as input and then performs the mathematical operation
selected by the user. To determine which operation to perform, the program uses a selection
statement. This program introduces you to if, elif, else statements which are used in many programs
when you give a user a choice.
1. Enter the following program in your text editor and save the file as calculator.py. Remember
that the code below may need to be fixed a bit for it to run correctly in the OnlineGDB editor:
#Simple Calculator
num1 = int(input("Enter a number: "))
num2 = int(input("Enter another number: "))
choice = input("Do you want to add, subtract, multiply, or divide? ")
if choice.upper() == "ADD":
answer = num1 + num2
print(num1, "+", num2, "=", answer)
elif choice.upper() == "SUBTRACT":
answer = num1 - num2
print(num1, "-", num2, "=", answer)
elif choice.upper() == "MULTIPLY":
answer = num1 * num2
print(num1, "*", num2, "=", answer)
elif choice.upper() == "DIVIDE":
answer = num1 / num2
print(num1, "/", num2, "=", answer)
else: print("Invalid input. Sorry!")
2. Please copy and paste your code into the OnlineGDB complier into the main.py area and run it.
3. Please take a screen shot of your code and the output from the OnlineGDB site and label it
Figure 2.
Answer the following questions about this program on the Answer Sheet:
• What is the purpose of the last else statement?
• With each of the if statements, choice.upper() is used. What is the purpose of the upper()
function and why is it used?
• The answer variable is used several times. Why is this variable for each instance not a
unique name like some of the other variables in the program?
• What is the purpose of the int function for the num1 and num2 variables?
• Why will the if statements not run unless they are indented?
• What is the difference between a single equal sign (=) and double equal sign (==) in the
programming code?
Program 3: Tunnels and Dragons Background
The original adventure game was text based. Gamers spent hours and hours immersed in a world of
caves, treasure, riddles, and dangers. In this lab, you will get into that retro vibe while designing the
gateway to an adventure game. It is a fun way to learn some programming basics and gain appreciation
for the programmer’s mind-set. In this program, you will use a while loop. Loops in programing are used
to check on user input until a certain number of times the loop is run.
1. Enter the following program in your text editor and save the file as adventure.py. Remember
that the code below may need to be fixed a bit for it to run correctly in the OnlineGDB editor:
# Adventure Game
#Trap the input so players must enter 1 or 2. You can use a while loop to check player input.
tunnelChoice = 0
while tunnelChoice < 1 or tunnelChoice > 2:
tunnelChoice = int(input("Choose tunnel 1 or tunnel 2: "))
print("You chose tunnel ", tunnelChoice)
if tunnelChoice == dangerTunnel:
print("You entered a tunnel with a dragon. Watch out!")
else:
print("You entered an empty tunnel. You are safe for now.")
2. Please copy and paste your code into the OnlineGDB complier into the main.py area and run it.
3. Please take a screen shot of your code and the output from the OnlineGDB site and label it
Figure 3.
Answer the following questions about this program on the Answer Sheet:
• When a dragon is in tunnel 1, do players who enter 1 get the "watch out" message?
• When the dragon is in tunnel 1, do players who enter 2 get the "safe" message?
• Comment out the While Loop, when players enter a number that is not 1 or 2, what
happens?
• Why is the While Loop very important to this program?
• When you enter a 1 or 2 as your choice, why do you not want these two choices to always
have the same result?
• What code is used to ensure that the danger tunnel is either tunnel 1 or 2 and not the same
tunnel all the time?
• What is the purpose of the variable tunnelChoice = 0 before the while loop?