SlideShare a Scribd company logo
Core Principles
of Programming
with python
Week 3
Main Menu
A main menu is what is displayed at the
start of any program.
It should be kept in a function and
mainly includes an IF statement.
An example of a main menu using last weeks
code is:
Remembering to use .upper() for validation.
Activity
Using what you have just learnt,
Help
• Remember to use IF and ELIF
statements for each option as
the ELSE statement should be
used if the user enters anything
that isn’t an option.
• Also remember to use .upper()
as a basic form of validation.
Create a main menu for your code from last week.
First Project Layout To achieve this, we will be using the
import command to import into our
project, our first Python library.
The layout of the project will be:
- Main Menu
- Rock Paper Scissors against AI
- Tic Tac Toe against either AI or another player
Setup Activity
Before we get ahead of ourselves:
Further activity
Create a new folder called “Python Game Project”.
Create a new file called “main.py”
Create a function for the main menu with three options:
• Rock Paper Scissors
• Tic Tac Toe
• Exit
Create two functions:
• rockpaperscissors()
• tictactoe()
The main menu should call these functions respectively
Try and place the main menu in a while loop for
validation, that is only exited if the user inputs the
exit choice of the menu.
The main menu should look like this
Console output:
The Further activity main menu should look like this
Console output:
Random Library
A library is a collection of prewritten python
functions that we can use.
The one we will be using today is the “random”
library.
Standard practice is to place all your imports at the
top of the code.
Random.randint() is the command to pick a number
between the first integer and the second integer
(including both of them).
An example of the random and random.randint()
code is:
This code will print a random number of either 1,
2, or 3.
Rock Paper Scissors
Now is the time to flex your skills.
I will let you guys crack on but here is how I would
lay out the program:
• Import random
• Ask the user what they would like to pick
• Print what the computer decided on (1 = Rock, 2
= Paper, 3 = Scissors)
• Compare the two values
• Print if it is a win, lose or draw
• Ask the user to play again (optional)
• Return to main menu
Help
• Compare the users input with
numbers to make your life easier
• Remember “AND” for comparing
values in the IF statement.
• There will be a lot of IF
statements in this program so do
not worry if you have a lot.
• Also remember to use .upper()
as a basic form of validation.
Rock Paper Scissors
For more help here is the comparison code:
• Import random
• Ask the user what they would like to pick
• compChoice = Randint(1,3)
• Convert that to a words
• Print what the computer decided on (1 = Rock, 2
= Paper, 3 = Scissors)
• Compare the two values
• Print if it is a win, lose or draw
• Ask the user to play again (optional)
• Return to main menu
Help
Rock Paper Scissors Here is the full code:
Arrays
An array is a special variable that can be used to
store multiple values in one single variable.
To access a value in the array you would write
the arrays name and then the index of the value
you want in square brackets.
An example of an array is:
0 1 2 3
This would print the word “Is”
as the first value of the array is
called 0.
Tic Tac Toe
Now this is the ultimate challenge.
How I would go about it:
• Create a Board Array to store what spots are empty.
• PrintTable() Function
• Pick which player one, will be (X or O)
• Compare the win conditions of the slots
• When the board is filled, print it was a draw.
• Ask the user to play again (optional)
• Return to main menu
Help
• Print the table with “–” and “|”
• Use board[x] to pick a certain
value in the list.
• Having the win conditions in a
test function will help you
repeatedly check if anyone has
won.
• Also remember to use numbers
for the nine slots.
Tic Tac Toe
Here is some code for printing the
board:
How I would go about it:
• Create a Board Array to store what spots are empty.
• PrintTable() Function
• Pick what player one will be (X or O)
• Compare the win conditions of the slots
• When the board is filled, print it was a draw.
• Ask the user to play again (optional)
• Return to main menu
Help
Tic Tac Toe
Here is some code for validation:
Help
The win conditions for Tic-Tac-Toe:
Tic Tac Toe
Here is the code for entering a position:
Tic Tac Toe
Here is the code for:
• Checking if anyone has won
• Swapping between players
• And asking the user if they want to play again.
Home Activity
Combining what you have learnt today,
Try and make a computer opponent version of Tic-Tac-Toe
using randint() to pick their turns.
End of week Three
And have a good Christmas

More Related Content

Similar to Week3.pptx

Basic use of Python
Basic use of PythonBasic use of Python
Basic use of Python
Yoshiki Satotani
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxPYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
swarna627082
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
PranavSB
 
python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
chandankumar943868
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
ysolanki78
 
Core Concept_Python.pptx
Core Concept_Python.pptxCore Concept_Python.pptx
Core Concept_Python.pptx
Ashwini Raut
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Michpice
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
Ruth Marvin
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari
 
ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1
UCLA Association of Computing Machinery
 
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptxLecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
AbdulQadeerBilal
 
Week 1.pptx
Week 1.pptxWeek 1.pptx
Week 1.pptx
WillSephton
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
gmadhu8
 
Python basics
Python basicsPython basics
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
Shivam Gupta
 
Python
PythonPython
Python
Shivam Gupta
 
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docxWeek 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
melbruce90096
 
Baabtra.com little coder chapter - 2
Baabtra.com little coder   chapter - 2Baabtra.com little coder   chapter - 2
Baabtra.com little coder chapter - 2
baabtra.com - No. 1 supplier of quality freshers
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptx
adihartanto7
 

Similar to Week3.pptx (20)

Basic use of Python
Basic use of PythonBasic use of Python
Basic use of Python
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxPYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
Core Concept_Python.pptx
Core Concept_Python.pptxCore Concept_Python.pptx
Core Concept_Python.pptx
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
 
Mastering Python lesson 3a
Mastering Python lesson 3aMastering Python lesson 3a
Mastering Python lesson 3a
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1ACM init() Spring 2015 Day 1
ACM init() Spring 2015 Day 1
 
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptxLecture-2-Python-Basic-Elements-Sep04-2018.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
 
Week 1.pptx
Week 1.pptxWeek 1.pptx
Week 1.pptx
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
 
Python basics
Python basicsPython basics
Python basics
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
Python
PythonPython
Python
 
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docxWeek 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
Week 2 iLab TCO 2 — Given a simple problem, design a solutio.docx
 
Baabtra.com little coder chapter - 2
Baabtra.com little coder   chapter - 2Baabtra.com little coder   chapter - 2
Baabtra.com little coder chapter - 2
 
Looping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptxLooping in PythonLab8 lecture slides.pptx
Looping in PythonLab8 lecture slides.pptx
 

Recently uploaded

➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
➒➌➎➏➑➐➋➑➐➐Dpboss Matka Guessing Satta Matka Kalyan Chart Indian Matka
 
The Evolution and Impact of Hip Hop a cultural and artistic
The Evolution and Impact of Hip Hop a cultural and artisticThe Evolution and Impact of Hip Hop a cultural and artistic
The Evolution and Impact of Hip Hop a cultural and artistic
applemusic056
 
➒➌➍➑➊➑➏➍➋➒ Satta Matka Satta result marka result Satta Matka Satta result mar...
➒➌➍➑➊➑➏➍➋➒ Satta Matka Satta result marka result Satta Matka Satta result mar...➒➌➍➑➊➑➏➍➋➒ Satta Matka Satta result marka result Satta Matka Satta result mar...
➒➌➍➑➊➑➏➍➋➒ Satta Matka Satta result marka result Satta Matka Satta result mar...
➒➌➍➑➊➑➏➍➋➒ Satta Matka Satta result marka result
 
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka KALYAN MATKA |
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka KALYAN MATKA |➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka KALYAN MATKA |
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka KALYAN MATKA |
➒➌➎➏➑➐➋➑➐➐Dpboss Matka Guessing Satta Matka Kalyan Chart Indian Matka
 
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing
➒➌➎➏➑➐➋➑➐➐Dpboss Matka Guessing Satta Matka Kalyan Chart Indian Matka
 
Class 12 Geography Practical file PDF.pdf
Class 12 Geography Practical file PDF.pdfClass 12 Geography Practical file PDF.pdf
Class 12 Geography Practical file PDF.pdf
ravisekhwat866
 
Subjectivity Subjectivity Subjectivity Subjectivity
Subjectivity Subjectivity Subjectivity SubjectivitySubjectivity Subjectivity Subjectivity Subjectivity
Subjectivity Subjectivity Subjectivity Subjectivity
hidetoshi4
 
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka Kalyan Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka Kalyan Matka➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka Kalyan Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka Kalyan Matka
➒➌➎➏➑➐➋➑➐➐Dpboss Matka Guessing Satta Matka Kalyan Chart Indian Matka
 
SSG Boorman Purple Heart found research.pdf
SSG Boorman Purple Heart found research.pdfSSG Boorman Purple Heart found research.pdf
SSG Boorman Purple Heart found research.pdf
rbakerj2
 
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
➒➌➎➏➑➐➋➑➐➐Dpboss Matka Guessing Satta Matka Kalyan Chart Indian Matka
 
The Cowherd and the Weaver Girl Storyboard
The Cowherd and the Weaver Girl StoryboardThe Cowherd and the Weaver Girl Storyboard
The Cowherd and the Weaver Girl Storyboard
Karina Young
 
"Snow" by Ann Beattie illustrated by Aimie Bourgeois
"Snow" by Ann Beattie illustrated by Aimie Bourgeois"Snow" by Ann Beattie illustrated by Aimie Bourgeois
"Snow" by Ann Beattie illustrated by Aimie Bourgeois
aimiebougie
 
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian MatkaDpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
➑➌➋➑➒➎➑➑➊➍
 
CPA112_R_v1.pdf_________________________
CPA112_R_v1.pdf_________________________CPA112_R_v1.pdf_________________________
CPA112_R_v1.pdf_________________________
AnnaPalindrome1
 
Graduate Film "A Perfect Meal" Storyboard
Graduate Film "A Perfect Meal" StoryboardGraduate Film "A Perfect Meal" Storyboard
Graduate Film "A Perfect Meal" Storyboard
Karina Young
 
Clouded storyboard why does the title need to be so long
Clouded storyboard why does the title need to be so longClouded storyboard why does the title need to be so long
Clouded storyboard why does the title need to be so long
Karina Young
 
Have a Nice Day Scene 3 .pdf
Have a Nice Day Scene 3              .pdfHave a Nice Day Scene 3              .pdf
Have a Nice Day Scene 3 .pdf
ElenaKrasteva9
 
Femmely-ACP-how to use social media to drive engagement
Femmely-ACP-how to use social media to drive engagementFemmely-ACP-how to use social media to drive engagement
Femmely-ACP-how to use social media to drive engagement
19jli3
 
239_FiveStarRestaurant_extract__________
239_FiveStarRestaurant_extract__________239_FiveStarRestaurant_extract__________
239_FiveStarRestaurant_extract__________
Nora Meek
 
Helpline number ➒➌➍➑➊➑➏➍➋➒ result update new market new business satta resul...
 Helpline number ➒➌➍➑➊➑➏➍➋➒ result update new market new business satta resul... Helpline number ➒➌➍➑➊➑➏➍➋➒ result update new market new business satta resul...
Helpline number ➒➌➍➑➊➑➏➍➋➒ result update new market new business satta resul...
➒➌➍➑➊➑➏➍➋➒ Satta Matka Satta result marka result
 

Recently uploaded (20)

➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
 
The Evolution and Impact of Hip Hop a cultural and artistic
The Evolution and Impact of Hip Hop a cultural and artisticThe Evolution and Impact of Hip Hop a cultural and artistic
The Evolution and Impact of Hip Hop a cultural and artistic
 
➒➌➍➑➊➑➏➍➋➒ Satta Matka Satta result marka result Satta Matka Satta result mar...
➒➌➍➑➊➑➏➍➋➒ Satta Matka Satta result marka result Satta Matka Satta result mar...➒➌➍➑➊➑➏➍➋➒ Satta Matka Satta result marka result Satta Matka Satta result mar...
➒➌➍➑➊➑➏➍➋➒ Satta Matka Satta result marka result Satta Matka Satta result mar...
 
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka KALYAN MATKA |
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka KALYAN MATKA |➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka KALYAN MATKA |
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka KALYAN MATKA |
 
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing
 
Class 12 Geography Practical file PDF.pdf
Class 12 Geography Practical file PDF.pdfClass 12 Geography Practical file PDF.pdf
Class 12 Geography Practical file PDF.pdf
 
Subjectivity Subjectivity Subjectivity Subjectivity
Subjectivity Subjectivity Subjectivity SubjectivitySubjectivity Subjectivity Subjectivity Subjectivity
Subjectivity Subjectivity Subjectivity Subjectivity
 
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka Kalyan Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka Kalyan Matka➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka Kalyan Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka Kalyan Matka
 
SSG Boorman Purple Heart found research.pdf
SSG Boorman Purple Heart found research.pdfSSG Boorman Purple Heart found research.pdf
SSG Boorman Purple Heart found research.pdf
 
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
➒➌➎➏➑➐➋➑➐➐ Satta Matka Dpboss Matka Guessing Indian Matka
 
The Cowherd and the Weaver Girl Storyboard
The Cowherd and the Weaver Girl StoryboardThe Cowherd and the Weaver Girl Storyboard
The Cowherd and the Weaver Girl Storyboard
 
"Snow" by Ann Beattie illustrated by Aimie Bourgeois
"Snow" by Ann Beattie illustrated by Aimie Bourgeois"Snow" by Ann Beattie illustrated by Aimie Bourgeois
"Snow" by Ann Beattie illustrated by Aimie Bourgeois
 
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian MatkaDpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
Dpboss Matka Guessing Satta Matta Matka Kalyan Chart Indian Matka
 
CPA112_R_v1.pdf_________________________
CPA112_R_v1.pdf_________________________CPA112_R_v1.pdf_________________________
CPA112_R_v1.pdf_________________________
 
Graduate Film "A Perfect Meal" Storyboard
Graduate Film "A Perfect Meal" StoryboardGraduate Film "A Perfect Meal" Storyboard
Graduate Film "A Perfect Meal" Storyboard
 
Clouded storyboard why does the title need to be so long
Clouded storyboard why does the title need to be so longClouded storyboard why does the title need to be so long
Clouded storyboard why does the title need to be so long
 
Have a Nice Day Scene 3 .pdf
Have a Nice Day Scene 3              .pdfHave a Nice Day Scene 3              .pdf
Have a Nice Day Scene 3 .pdf
 
Femmely-ACP-how to use social media to drive engagement
Femmely-ACP-how to use social media to drive engagementFemmely-ACP-how to use social media to drive engagement
Femmely-ACP-how to use social media to drive engagement
 
239_FiveStarRestaurant_extract__________
239_FiveStarRestaurant_extract__________239_FiveStarRestaurant_extract__________
239_FiveStarRestaurant_extract__________
 
Helpline number ➒➌➍➑➊➑➏➍➋➒ result update new market new business satta resul...
 Helpline number ➒➌➍➑➊➑➏➍➋➒ result update new market new business satta resul... Helpline number ➒➌➍➑➊➑➏➍➋➒ result update new market new business satta resul...
Helpline number ➒➌➍➑➊➑➏➍➋➒ result update new market new business satta resul...
 

Week3.pptx

  • 2. Main Menu A main menu is what is displayed at the start of any program. It should be kept in a function and mainly includes an IF statement. An example of a main menu using last weeks code is: Remembering to use .upper() for validation.
  • 3. Activity Using what you have just learnt, Help • Remember to use IF and ELIF statements for each option as the ELSE statement should be used if the user enters anything that isn’t an option. • Also remember to use .upper() as a basic form of validation. Create a main menu for your code from last week.
  • 4. First Project Layout To achieve this, we will be using the import command to import into our project, our first Python library. The layout of the project will be: - Main Menu - Rock Paper Scissors against AI - Tic Tac Toe against either AI or another player
  • 5. Setup Activity Before we get ahead of ourselves: Further activity Create a new folder called “Python Game Project”. Create a new file called “main.py” Create a function for the main menu with three options: • Rock Paper Scissors • Tic Tac Toe • Exit Create two functions: • rockpaperscissors() • tictactoe() The main menu should call these functions respectively Try and place the main menu in a while loop for validation, that is only exited if the user inputs the exit choice of the menu.
  • 6. The main menu should look like this Console output:
  • 7. The Further activity main menu should look like this Console output:
  • 8. Random Library A library is a collection of prewritten python functions that we can use. The one we will be using today is the “random” library. Standard practice is to place all your imports at the top of the code. Random.randint() is the command to pick a number between the first integer and the second integer (including both of them). An example of the random and random.randint() code is: This code will print a random number of either 1, 2, or 3.
  • 9. Rock Paper Scissors Now is the time to flex your skills. I will let you guys crack on but here is how I would lay out the program: • Import random • Ask the user what they would like to pick • Print what the computer decided on (1 = Rock, 2 = Paper, 3 = Scissors) • Compare the two values • Print if it is a win, lose or draw • Ask the user to play again (optional) • Return to main menu Help • Compare the users input with numbers to make your life easier • Remember “AND” for comparing values in the IF statement. • There will be a lot of IF statements in this program so do not worry if you have a lot. • Also remember to use .upper() as a basic form of validation.
  • 10. Rock Paper Scissors For more help here is the comparison code: • Import random • Ask the user what they would like to pick • compChoice = Randint(1,3) • Convert that to a words • Print what the computer decided on (1 = Rock, 2 = Paper, 3 = Scissors) • Compare the two values • Print if it is a win, lose or draw • Ask the user to play again (optional) • Return to main menu Help
  • 11. Rock Paper Scissors Here is the full code:
  • 12. Arrays An array is a special variable that can be used to store multiple values in one single variable. To access a value in the array you would write the arrays name and then the index of the value you want in square brackets. An example of an array is: 0 1 2 3 This would print the word “Is” as the first value of the array is called 0.
  • 13. Tic Tac Toe Now this is the ultimate challenge. How I would go about it: • Create a Board Array to store what spots are empty. • PrintTable() Function • Pick which player one, will be (X or O) • Compare the win conditions of the slots • When the board is filled, print it was a draw. • Ask the user to play again (optional) • Return to main menu Help • Print the table with “–” and “|” • Use board[x] to pick a certain value in the list. • Having the win conditions in a test function will help you repeatedly check if anyone has won. • Also remember to use numbers for the nine slots.
  • 14. Tic Tac Toe Here is some code for printing the board: How I would go about it: • Create a Board Array to store what spots are empty. • PrintTable() Function • Pick what player one will be (X or O) • Compare the win conditions of the slots • When the board is filled, print it was a draw. • Ask the user to play again (optional) • Return to main menu Help
  • 15. Tic Tac Toe Here is some code for validation: Help The win conditions for Tic-Tac-Toe:
  • 16. Tic Tac Toe Here is the code for entering a position:
  • 17. Tic Tac Toe Here is the code for: • Checking if anyone has won • Swapping between players • And asking the user if they want to play again.
  • 18. Home Activity Combining what you have learnt today, Try and make a computer opponent version of Tic-Tac-Toe using randint() to pick their turns.
  • 19. End of week Three And have a good Christmas