Example Python Journal Submission
Example Python Journal Submission
Directions: Follow the directions for each part of the journal template. Include in your response
all the elements listed under the Requirements section. Prompts in the Inspiration section are
not required; however, they may help you to fully think through your response.
Remember to review the Touchstone page for entry requirements, examples, and grading
specifics.
Name: Learner
Date: 03/15/2022
Final Replit Program Share Link:
https://replit.com/@Sophia-IPP-Replit/Unit4-Final-Demo#main.py
Complete the following template. Fill out all entries using complete sentences.
Task
State the problem you are planning to solve.
Requirements
● Describe the problem you are trying to solve for.
● Describe any input data you expect to use.
● Describe what the program will do to solve the problem.
● Describe any outputs or results the program will provide.
Inspiration
When writing your entry below ask yourself the following questions:
● Why do you want to solve this particular problem?
● What source(s) of data do you believe you will need? Will the user need to supply that data, or
will you get it from an external file or another source?
● Will you need to interact with the user throughout the program? Will users continually need to
enter data in and see something to continue?
● What are your expected results or what will be the end product? What will you need to tell a
user of your program when it is complete?
Casino craps is a dice game in which players bet on the outcome of the roll of a pair of dice. The
problem to solve is to help a user better understand the odds of winning and losing at casino craps at
an actual casino. I will create a simulation of the craps game to solve this problem. When executed,
the program will first provide a sample game as an example for the user. Second, the program will
ask the user to input the number of games to play. The program will play the requested number of
games. After the last game is played, the program will output (display) the results of the games. The
program will store a record of the simulations in an external log file. By playing the game multiple
times and reviewing the statistics, users will get a better understanding of their chances of winning.
Task
Write down clear and specific steps to solve a simple version of your problem you identified in Part 1.
Requirements
Complete the three steps below for at least two distinct examples/scenarios.
● State any necessary input data for your simplified problem.
● Write clear and specific steps in English (not Python) detailing what the program will do to
solve the problem.
● Describe the specific result of your example/scenario.
Inspiration
When writing your entry below ask yourself the following questions:
● Are there any steps that you don’t fully understand? These are places to spend more time
working out the details. Consider adding additional smaller steps in these spots.
● Remember that a computer program is very literal. Are there any steps that are unclear? Try
giving the steps of your example/scenario to a friend or family member to read through and
ask you questions about parts they don’t understand. Rewrite these parts as clearly as you
can.
● Are there interesting edge cases for your program? Try to start one of your
examples/scenarios with input that matches this edge case. How does it change how your
program might work?
1. Roll two six-sided random dice for the first time, getting a 1 and a 2.
2. Add the values on the top of the two dice, getting 3.
3. The player loses the game.
1. Roll two six-sided random dice for the first time, getting a 3 and a 4.
2. Add the values on the top of the two dice, getting 7.
3. The player wins the game.
1. Roll two six-sided random dice for the first time, getting a 1 and a 4.
2. Add the values on the top of the two dice, getting 5.
3. The value is not 2, 3, 7, 11, or 12, so the game continues.
4. Roll the two dice again, getting a 3 and a 6.
Task
Write out the general sequence your program will use, including all specific examples/scenarios you
provided in Part 2.
Requirements
● Write pseudocode for the program in English but refer to Python program elements where
they are appropriate. The pseudocode should represent the full functionality of the program,
not just a simplified version. Pseudocode is broken down enough that the details of the
program are no longer in any paragraph form. One statement per line is ideal.
Inspiration
When writing your entry below ask yourself the following questions:
● Do you see common program elements and patterns in your specific examples/scenarios in
Part 2, like variables, conditionals, functions, loops, and classes? These should be part of
your pseudocode for the general sequence as well.
● Are there places where the steps for your examples/scenarios in Part 2 diverged? These may
be places where errors may occur later in the project. Make note of them.
● When you are finished with your pseudocode, does it make sense, even to a person that does
not know Python? Aim for the clearest description of the steps, as this will make it easier to
convert into program code later.
Function play()
Set the rolled value to roll first dice + roll second dice
If the rolled value is equal to 2, 3 or 12
Set player status to lose
Else If the rolled value is equal to 7 or 11
Set player status to win
Else
Set point value to rolled value
Set the rolled value to roll first dice + roll second dice
If the rolled value is equal to 7
Set player status to lose
Else If rolled value is equal to point value
Set player status to win
Main Program
Set Wins = 0
Set Losses = 0
Set Total of Win Rolls = 0
Set Total of Loss Rolls = 0
Set Games Played to 0
Task
While writing and testing your program code, describe your tests, record any errors, and state your
approach to fixing the errors.
Requirements
● For each test case, describe how your choices for the test helped you understand whether the
program was running correctly or not.
For each error that occurs while writing and testing your code:
● Record the details of the error from Replit. A screenshot or copy-and-paste of the text into the
journal entry is acceptable.
● Describe what you attempted in order to fix the error. Clearly identify what approach was the
one that worked.
Inspiration
When writing your entry below ask yourself the following questions:
● Have you tested edge cases and special cases for the inputs of your program code? Often
these unexpected values can cause errors in the operation of your program.
● Have you tested opportunities for user error? If a user is asked to provide an input, what
happens when they give the wrong type of input, like a letter instead of a number, or vice
versa?
After changing my initial code in the main program to check for invalid user entries by adding the try
and except statements, I noticed it handled the invaid input (no error) but would stop after that and
not request another entry from the user. Here was my initial code:
def main():
#play one game
print("Running one sample game in full:")
playOneGame()
number = 0
#play multiple games based on the entry by the user
user_input = input("How many games would you want to have tested: ")
try:
number = int(user_input)
playMultipleGames(number)
except ValueError:
print("Please enter in a number for the number of games.")
And the output did handle the exception of the letter “a” as input but the program stopped. The output
looking like this.
def main():
#play one game
print("Running one sample game in full:")
playOneGame()
number = 0
#play multiple games based on the entry by the user
while number == 0:
user_input = input("How many games would you want to have tested: ")
try:
number = int(user_input)
playMultipleGames(number)
except ValueError:
print("Please enter in a number for the number of games.")
Now after adding in the <code>while</code> loop, I ran the code again and entered in the letter “a”
as input. When doing so, the program then prompted me again to enter in the number of games
rather than ending the program. This solves the issue of the program ending now.
Task
Submit your full program code, including thorough comments describing what each portion of the
program should do when working correctly.
Requirements
● The purpose of the program and each of its parts should be clear to a reader that does not
know the Python programming language.
Inspiration
When writing your entry, you are encouraged to consider the following:
● Is each section or sub-section of your code commented to describe what the code is doing?
● Give your code with comments to a friend or family member to review. Add additional
comments to spots that confuse them to make it clearer.
Comments are colored in red. There are three modules/classes to this program.
#This function is created to play a single game and print out the results after each roll.
def playOneGame():
player = Player()
while not player.isWinner() and not player.isLoser():
player.rollDice()
print(player)
if player.isWinner():
print("You win!")
else:
print("You lose!")
#This function is created to play multiple games and outputs the results based on the number of
games selected.
#This function will log each multi game run to include the date/time and the details of the run
def logStats(wins, losses, winRolls, lossRolls, number):
file = open("log.txt", "a")
if __name__ == "__main__":
main()
#We will first import the class Die that we have created
from die import Die
#The class Player is the functionality that makes use of the Die class.
class Player(object):
#The __init__ method will create a pair of dice and initialize the other variables.
def __init__(self):
self.firstDie = Die()
self.secondDie = Die()
self.roll = ""
self.rollsCount = 0
self.startOfGame = True
self.winner = self.loser = False
#The logic of the game is now running, if this is the first game
if self.startOfGame:
#Initial value is set to the the value of the two dice
self.initialSum = v1 + v2
self.startOfGame = False
#If the initial sum is equal to 2, 3 or 12, the player is set to have lost
if self.initialSum in (2, 3, 12):
self.loser = True
#If the initial sum is equal to 7 or 11, the player is set to have won
elif self.initialSum in (7, 11):
self.winner = True
#If this is not the first game
else:
#We are now checking for the later sum of the values
laterSum = v1 + v2
#if it's not the start of the game and a 7 is rolled, the player loses
if laterSum == 7:
self.loser = True
#If the player rolled the same sum as the first sum, the player wins
elif laterSum == self.initialSum:
self.winner = True
return (v1, v2)
#With the game, it's possible that both isWinner and isLower is false
#If this is the case, the game is not finished and we must roll again until one is true.
#Plays a full game and counts the rolls for that game.
#This returns True for a win and False if the player loses
def play(self):
#We continue to roll as long as both are False
while not self.isWinner() and not self.isLoser():
self.rollDice()
return self.isWinner()
class Die:
#The __init__ method is used to create a new instance of die with a default value of 1
def __init__(self):
self.value = 1
#The roll method is used to set the value to a random number between 1 and 6
def roll(self):
self.value = randint(1, 6)
#The getValue method returns the top face value of the die
def getValue(self):
return self.value
#The __str__ method returns the string representation of the value of the die
def __str__(self):
return str(self.getValue())
Task
Provide the Replit link to your full program code.
Requirements
● The program must work correctly with all the comments included in the program.
Inspiration
● Check before submitting your touchstone that your final version of the program is running
successfully.
https://replit.com/@Sophia-IPP-Replit/Unit4-Final-Demo#main.py