Python Journal Template

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Python Journal Template

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: HOWARD ADENIYI


Date: 04/09/2024
Final Replit Program Share Link: https://replit.com/@howard8/Python#main.py

Complete the following template. Fill out all entries using complete sentences.

Python Journal Template 1


PART 1: Defining Your Problem

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?

<Write your journal entry response here>

The problem I aim to solve is to help players better understand the odds of winning and losing in the
Megamillions lottery game. Many people participate in this lottery, but few understand the actual
likelihood of winning different prize tiers based on the numbers they select. The input data for this
program will consist of the player's chosen numbers for each play. Additionally, we will need the
winning numbers for each drawing to determine if the player has won or lost. The program will
generate random sets of winning numbers for each Megamillions drawing. It will then prompt the user
to input their chosen numbers for a play. After receiving the player's numbers, the program will
compare them with the winning numbers to determine if the player has won any prizes.

It will calculate and display the odds of winning different prize tiers based on the matching numbers.
This will help the player understand their chances of winning various prizes in the Megamillions
lottery game. The source of data needed will be the winning numbers for each Megamillions drawing,
which can be obtained from official lottery websites or databases. Interaction with the user will be
required to input their chosen numbers for each play. Users may need to enter data continuously to
participate in multiple plays. The expected result is to provide users with a better understanding of
their odds of winning different prize tiers in the Megamillions lottery. The end product will be a

Python Journal Template 2


program that informs users about their chances of winning based on the numbers they choose to
play.

Python Journal Template 3


PART 2: Working Through Specific Examples

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?

<Write your journal entry response here>

Scenario 1: Single Play


Input Data:
 Player's chosen numbers: [5, 10, 15, 20, 25] (chosen randomly for demonstration purposes)
 Winning numbers: [7, 12, 15, 19, 25] (generated randomly for demonstration purposes)
Steps to Solve:
1. Generate random winning numbers for the Megamillions drawing.
2. Prompt the player to input their chosen numbers for the play.
3. Compare the player's chosen numbers with the winning numbers.
4. Determine if any of the player's numbers match the winning numbers.
5. If there are no matches, inform the player that they have lost and display the winning
numbers.
6. If there are matches, calculate the number of matching numbers.
7. Display the matching numbers and inform the player of their winnings based on the number of

Python Journal Template 4


matches.
8. End the play.
Result:
 In this scenario, let's assume that the player's chosen numbers [5, 10, 15, 20, 25] have a
single match with the winning numbers [7, 12, 15, 19, 25]. The program will inform the player
of their win and display the matching number. The player will be excited to have won a prize,
even though it may not be the jackpot. This scenario demonstrates a simple play in the
Megamillions lottery, where the player experiences the excitement of winning a prize.

Scenario 2: Multiple Plays


Input Data:
 Player's chosen numbers for each play:
 Play 1: [3, 6, 9, 12, 15]
 Play 2: [2, 5, 8, 11, 14]
 Play 3: [1, 4, 7, 10, 13]
 Winning numbers for each play (generated randomly for demonstration purposes)
Steps to Solve:
1. Generate random winning numbers for each Megamillions drawing (for each play).
2. Loop through each play: a. Prompt the player to input their chosen numbers. b. Compare the
player's chosen numbers with the winning numbers. c. Determine if any of the player's
numbers match the winning numbers. d. If there are no matches, inform the player that they
have lost and display the winning numbers. e. If there are matches, calculate the number of
matching numbers. f. Display the matching numbers and inform the player of their winnings
based on the number of matches.
3. End the plays.
Result:
 In this scenario, the program simulates multiple plays of the Megamillions lottery with different
sets of chosen numbers. For each play, the program determines if the player has won any
prizes based on the matching numbers. The player experiences the thrill of anticipation with
each play and learns about their odds of winning prizes in the lottery. This scenario
demonstrates the functionality of the program for handling multiple plays of the Megamillions
lottery.

Python Journal Template 5


PART 3: Generalizing Into Pseudocode

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.

Help with writing pseudocode


● Here are a few links that can help you write pseudocode with examples. Remember to check
out part 3 of the Example Journal Template Submission if you have not already. Note:
everyone will write pseudocode differently. There is no right or wrong way to write it other
than to make sure you write it clearly and in as much detail as you can so that it should be
easy to convert it to code later.
○ https://www.geeksforgeeks.org/how-to-write-a-pseudo-code/
○ https://www.wikihow.com/Write-Pseudocode

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.

Python Journal Template 6


<Write your pseudocode here>

Generate_Winning_Numbers() Function:
 Define Generate_Winning_Numbers() function to generate random winning numbers.
 Use random number generator to create a list of 5 unique numbers within the range of
1 to 70.
 Return the list of winning numbers.

Play_Megamillions() Function:
 Define Play_Megamillions() function to simulate a single play of the Megamillions
lottery.
 Prompt the player to input their chosen numbers.
 Compare the player's chosen numbers with the winning numbers generated using
Generate_Winning_Numbers() function.
 Determine if any of the player's numbers match the winning numbers.
 If there are no matches, inform the player that they have lost and display the winning
numbers.
 If there are matches, calculate the number of matching numbers.
 Display the matching numbers and inform the player of their winnings based on the
number of matches.

Multiple_Plays() Function:
 Define Multiple_Plays() function to simulate multiple plays of the Megamillions lottery.
 Prompt the player to input the number of plays they want to simulate.
 Loop through each play:
 Call Play_Megamillions() function to simulate a single play.
 Repeat until the specified number of plays is reached.
 End the plays.

Main Program:
 Call Multiple_Plays() function to start simulating multiple plays of the Megamillions
lottery.
 Display the results of each play to the player.
 End the program.

Python Journal Template 7


PART 4: Testing Your Program

Task
While writing and testing your program code, describe your tests, record any errors, and state your
approach to fixing the errors.

Requirements
● For at least one of your test cases, 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?
● Did the outcome look the way you expected? Was it formatted correctly?

● Does your output align with the solution to the problem you coded for?

Python Journal Template 8


<Record your errors and fixes here>

During the development and testing of the Megamillions lottery simulation program, I performed
various tests to ensure the correctness and robustness of the code.

1. Test Case: Single Play with Winning Numbers


 Description: Input the winning numbers as the player's chosen numbers.
 Expected Result: The program should correctly identify all matching numbers and
declare the player as the winner.
 Test Outcome: The program correctly identified all matching numbers and declared
the player as the winner.

2. Test Case: Single Play with No Matching Numbers


 Description: Input random numbers that do not match any of the winning numbers.
 Expected Result: The program should correctly identify no matching numbers and
declare the player as not winning.
 Test Outcome: The program correctly identified no matching numbers and declared
the player as not winning.

3. Test Case: Multiple Plays


 Description: Simulate multiple plays of the lottery.
 Expected Result: The program should simulate the specified number of plays and
provide the outcome for each play.
 Test Outcome: The program successfully simulated the specified number of plays and
provided the outcome for each play.

4. Test Case: Invalid Input Type


 Description: Input non-numeric values for the player's chosen numbers.
 Expected Result: The program should handle the error gracefully and prompt the user
to input valid numeric values.
 Test Outcome: The program raised a ValueError when non-numeric values were
input, prompting the user to input valid numeric values.

5. Test Case: Invalid Number of Chosen Numbers


 Description: Input fewer or more than 5 numbers for the player's chosen numbers.
 Expected Result: The program should handle the error gracefully and prompt the user
to input exactly 5 numbers.
 Test Outcome: The program raised a ValueError when fewer or more than 5 numbers
were input, prompting the user to input exactly 5 numbers.

6. Test Case: Negative Number Input


 Description: Input negative numbers for the player's chosen numbers.
 Expected Result: The program should handle the error gracefully and prompt the user
to input non-negative numbers.

Python Journal Template 9


 Test Outcome: The program raised a ValueError when negative numbers were input,
prompting the user to input non-negative numbers.

Error Details:
 Error Message: ValueError: invalid literal for int() with base 10: 'abc'
 Description: The error occurred when non-numeric values were input for the player's chosen
numbers.
 Approach to Fix: I added a try-except block around the conversion of input to integers in the
play_megamillions() function to catch the ValueError and prompt the user to input valid
numeric values. This approach worked, and the program handled the error gracefully.

Below is an example of the error encountered during testing:

Enter your 5 chosen numbers (separated by spaces): abc d e 1 2


Traceback (most recent call last):
File "main.py", line 22, in <module>
multiple_plays()
File "main.py", line 17, in multiple_plays
play_megamillions()
File "main.py", line 9, in play_megamillions
player_numbers = [int(num) for num in input("Enter your 5 chosen numbers (separated by spaces):
").split()]
ValueError: invalid literal for int() with base 10: 'abc'

PART 5: Commenting Your Program

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.

Python Journal Template 10


<Copy your full program code here, including comments>

This program simulates the Megamillions lottery game. Here's a breakdown of each part of the code:
1. generate_winning_numbers(): This function generates a list of 5 unique random numbers
between 1 and 70, representing the winning numbers for the Megamillions lottery.
2. play_megamillions(): This function simulates a single play of the Megamillions lottery game.
It prompts the player to enter their chosen numbers, validates the input, and returns the
player's chosen numbers.
3. check_results(): This function compares the winning numbers with the player's chosen
numbers to determine whether the player won or lost. It counts the number of matching
numbers and returns a message indicating the outcome.
4. multiple_plays(): This function simulates multiple plays of the Megamillions lottery game. It
prompts the user to specify the number of plays to simulate, generates the winning numbers,
and then iterates over each play, prompting the player to enter their chosen numbers and
displaying the outcome of each play.
The main program executes the multiple_plays() function when the script is run, initiating the
simulation of multiple plays of the Megamillions lottery game.

---The Main.py file----

import random

def generate_winning_numbers():
"""
Generates a list of 5 unique random numbers as the winning numbers for the Megamillions lottery.

Returns:
list: A list containing 5 unique random numbers.
"""
return random.sample(range(1, 71), 5)

def play_megamillions():
"""
Simulates a single play of the Megamillions lottery game.

Returns:
list: A list containing the player's chosen numbers.
"""
try:
player_numbers = [int(num) for num in input("Enter your 5 chosen numbers (separated by
spaces): ").split()]
if len(player_numbers) != 5:

Python Journal Template 11


raise ValueError("You must enter exactly 5 numbers.")
if not all(1 <= num <= 70 for num in player_numbers):
raise ValueError("Numbers must be between 1 and 70.")
return player_numbers
except ValueError as ve:
print("Invalid input:", ve)
return None

def check_results(winning_numbers, player_numbers):


"""
Compares the winning numbers with the player's chosen numbers to determine the outcome.

Args:
winning_numbers (list): A list containing the winning numbers.
player_numbers (list): A list containing the player's chosen numbers.

Returns:
str: A message indicating whether the player won or lost.
"""
matching_numbers = set(winning_numbers) & set(player_numbers)
if len(matching_numbers) >= 3:
return "Congratulations! You won!"
else:
return "Sorry, you did not win this time. Better luck next time!"

def multiple_plays():
"""
Simulates multiple plays of the Megamillions lottery game.
"""
num_plays = int(input("How many plays would you like to simulate? "))
winning_numbers = generate_winning_numbers()
for i in range(1, num_plays + 1):
print("\nPlay", i)
player_numbers = play_megamillions()
if player_numbers is not None:
print("Winning Numbers:", winning_numbers)
print("Player's Numbers:", player_numbers)
print(check_results(winning_numbers, player_numbers))

# Main program
if __name__ == "__main__":
multiple_plays()

Python Journal Template 12


PART 6: Your Completed Program

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.

<Provide the link to your program here>

https://replit.com/@howard8/Python#main.py

Python Journal Template 13

You might also like