Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
19 views
Computer Application
Computer technology
Uploaded by
pavi2004g
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Computer application For Later
Download
Save
Save Computer application For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
19 views
Computer Application
Computer technology
Uploaded by
pavi2004g
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Computer application For Later
Carousel Previous
Carousel Next
Save
Save Computer application For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 11
Search
Fullscreen
BEASANT TECHNOLOGIES A Project reportes On “ROCK PAPER SCISSORS” For the course PYTHON PROGRAMMIN NG LANGUAGE 2 ssn y - PAVITHRA G SUBMITTED TO COORDINATOR GOWTHAMI INBA @ scanned with OKEN ScannerCONCEPT OF ROCK paper scissior Python program to implement Rock Paper Scissors game python is a multipurpose language any one can do anything with it python can also be used for game development.let's create a simple command-line Rock-paper-scissior game without using any external game, user gets the first chance pick the option between Rock,Paper,and Scissors.After the computer select from the remaining two choices(randomly),the winner is decided as per the rules Winning rules as follows: Rock vs paper->paper wins Rock vs Scissor->Rock wins Paper vs Scissor->Scissor wins BASIC ROCK PAPER SCISSORS PYTHON PROGRAM To understand the program below, you should have a basic idea About the following python concepts: > Python Random module > python loops Play a single game of rock paper scissors in python Using the description and rules above,you can make a game of Rock paper scissors. before you dive in you're going to need to import The module you ‘Il use to simulate the computer's choices: Import random Awesome! Now you're able to use the different tools inside random To randomize the computer's actions in the game. Now what? Since You need to be able to choose their action . @ scanned with OKEN ScannerSOURCE CODE: Ty 3 x te Yor totems oe Bee auael £/ M4) ZIG 8 Pik 6/9 9\clm| 2l@ 1 Fore. and 2 print(*\relcone to Rock, Paper, Scissors!") 3 player-eine = 2 gahite Troet, + Po ptayer = inevecrintnter » choice (rock, paper, sctasors)! ") + | Gholees = Cerock"y spupersy sactsors"] + | Soputer = candonchoice(chosces) + | prinecf"\nvou chose (player), computer chose (comuter)") Bf af player = computers 2 princ(foBoth players selected (player). Te 4s a tie!*) Bb elit player = reece 1 conuter = "aeissorst . print("Rock aneshes scissors. You wit") * player wtnert " eset prine(*Paper covers rock, You lose.) Bh ati player i 4 contr 2 print("Paper covers rock. You win") i Player wine IM tset te prine("Setssors cut t Computer xine = rine(scieere cate papers You win") a player wiaecl m eset Print(“Rock anashes scissors. You Lose") fe emptor ie ss | prinecs\nvou have *este(ptayerwins)+* wins") se | prinetthe conuter has "+str(computer wins) wins a8 input("\nPlay again? (yes/no): ") 3 ower) ie prine(*Thank ls Break letras cats 1/8 tal Sd n= Cee = LED Une CRE HS 5 Penton @ scanned with OKEN ScannerDESCRIPTION CODE: Step 1: Open a text editor Step 2: Use the import statement import random The import statement loads module contents for later access and use. When an import statement is executed, the standard built-in _import_( function is called. The random module is a built-in module to generate random variables. We are going to use it to make computer choose a random value among rock, paper, and scissors each game we play. Step 3: Print introduction line print("Welcome to Rock, Paper, Scissors! \n") Make sure to use double quotes because strings must be enclosed in double quotes for the data to be recognized as a string, not a number or variable name. A backslash n (\n) is called a new line and used inside the print statement to create a new line as its name indicates. Step 4: Set win counters player_wins =0 computer_wins = 0 Assign a value of 0 to win counter variables. Step 5: Use While statement while True: player = input("Enter a choice (rock, paper, scissors): ") choices = ["rock", "paper", "scissors"] @ scanned with OKEN Scannercomputer = random.choice(choices) print(f"\nYou chose {player}, computer chose {computer}.") While True means loop forever. In other words, the while loop will run as long as the While condition is True. You can force the loop to end by using the break statement. Create an input variable where players can enter a value among rock, paper, scissors. Create a list containing the rock, paper, scissors values with brackets. We will call the list “choices”. Then, we are going to use the random module here. Create a random.choice variable. The choice() function here is used to randomly select an item from a list. Print the game status information .The fwith curly braces is called f-string,and it lets you include The value python expression inside a string. Step 6: Use if statement If player==computer: Print(“both players selected{player}.it is a tie!”) Elif player=="rock”: If computer =="scissiors”: Print(“Rock smashes scissord.You win!”) Player_wins+1 Else: Print(“paper covers rock.you lose.”) Computer_wins+=1 @ scanned with OKEN Scannerprint("Paper covers rock. You win!") player_wins+=1 else: print("Scissors cuts paper. You lose.") computer_wins+=1 elif player == "scissors": if computer == "paper": print("Scissors cuts paper. You win!") player_wins+=1 else: print("Rock smashes scissors. You lose.") computer_wins+=1 Note that an if block can go under another if block. Step 7: Print the win counters print("You have "+str(player_wins)+" wins") print("The computer has "+str(computer_wins)+" wins") The str() function converts the specified value into a string. Instead of the str() function, you can use f-strings as follows: print(f"You have {player_wins} wins") print(f"The computer has {computer_wins} wins") @ scanned with OKEN ScannerStep 8: Ask to quit or play again repeat = input(""\nPlay again? (yes/no): ") if repeat.lower() != "yes": print("Thanks for playing!") break Create a repeat variable where players can enter a value between yes or no. The lower() method returns the lowercase string from the given string. The exclamation mark with an equal sign (!=) is called not equal to operator. If players enter any value other than yes, the while statement stops operating because of the following break statement. The break statement terminates the current loop. It can be used in both while and for loops. Congratulations! You've just built a rock-paper-scissors game in Python. Below is the entire code: Below is the entire code: import random print("Welcome to Rock, Paper, Scissors!\n") player_wins =0 computer_wins=0 while True: player=input(“Enter a choice(rock,paper,scissors):”) choices=[“rock”,”paper”,”scissors”] computer=random.choice(choices) @ scanned with OKEN Scannerprint(“f’\nYou choose{player},computer choose{computer}.”) if player == computer: print(f"Both players selected {player}. It is a tie!") © if player == "rock": if computer == "scissors": rint("Rock smashes scissors. You win!") p player_wins+=1 else: p rint("Paper covers rock. You lose.") computer_wins+=1 e if player if computer == rint("Paper covers rock. You win!") p player_wins+=1 else: p rint("Scissors cuts paper. You lose.") computer_wins+=1 © if player == "scissors": if computer == "paper": print("Scissors cuts paper. You win!") player_wins+=1 else: @ scanned with OKEN Scannerprint("Rock smashes scissors. You lose.") computer_wins+=1 print("You have "+str(player_wins)+" wins") print('The computer has "+str(computer_wins)+" wins") repeat = input("\nPlay again? (yes/no): ") if repeat.lower() != "yes": print ("Thanks for playing!") Break @ scanned with OKEN ScannerOUTPUT: Scanned with OKEN ScannerCONCLUSION: We have learned what a rock, paper and scissors game is and the rules to play this game. We also learnt how to create a simple rock paper scissor game in Python. While this game in python may seem basic, it’s a great starting point for learning programming concepts like conditional statements, functions, and modules. As you become more comfortable with Python, you can add more features to the game, such as keeping score, allowing inputs from the users that are not case sensitive and allowing the user to play multiple rounds. With a little creativity, you can create a fun and engaging game that people will enjoy playing.Coding for kids has many beneficial advantages that clevelop cognitive abilities, enhance communication and entrepreneurship skills, and stimulate creativity. Kids can learn how to create different games using @ scanned with OKEN Scanner
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6125)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8214)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2922)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2530)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Yes Please
From Everand
Yes Please
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel