by freeCodeCamp.org
Learn Python programming basics by building a rock-paper-scissors game
A beginner-friendly introduction to Python programming. Learn variables, functions, dictionaries, and user input by building an interactive rock-paper-scissors game in the browser using Replit.
Go to replit.com and create a new Python replit to start coding in your browser.
Define variables using descriptive names. In Python, use underscores for spaces. Assign values with the = operator and use quotes for strings.
Example: player_choice = 'rock'
Create reusable code blocks with def followed by the function name and a colon. Indent the code inside the function.
Use return to send values back from the function.
Store key-value pairs in dictionaries using curly braces. Access values by their keys.
Example: {'player': 'rock', 'computer': 'paper'}
Use the input() function to prompt the user and store their response in a variable.
Example: player_choice = input('Enter a choice: ')
Import the random library at the top of your file to make random choices for the computer.
Example: import random