0% found this document useful (0 votes)
14 views8 pages

Mini Project

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

Mini Project

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

MINI PROJRCT

By
Prajwal date

chandu

project name
Rock paper scissor(a player with a robot)
Steps;
Algarithom
Flow chart
code

explanation

>>Initialize Random Seed:*

- Import the random module.

>>Start Main Loop:*

- Begin an infinite loop to allow continuous play.

>>Display Choices:*
- Print "1. Rock, 2. Scissors, 3. Paper".

>>User Input:*

- Prompt the user to enter a number (1, 2, or 3).

- Validate the user input to ensure it is between 1 and 3.

- If the input is invalid, prompt the user again until a valid input is received.

>>Map User Input to Choice:*

- Map the user input number to its corresponding choice (1 to 'Rock', 2 to 'Scissors', 3 to 'Paper').

- Print the user's choice.

>>Generate Device Choice:*

- Use random.randint(1, 3) to generate a random number for the device's choice.

- Ensure the device's choice is different from the user's choice:

- If the choices are the same, regenerate the device's choice until they differ.

>>Map Device Input to Choice:*

- Map the device's choice number to its corresponding choice (1 to 'Rock', 2 to 'Scissors', 3 to 'Paper').

- Print the device's choice.

>>Determine the Winner:*

- Compare the user’s choice and the device’s choice to determine the winner:

- If (user_choice is 'Rock' and device_choice is 'Scissors') or (user_choice is 'Scissors' and


device_choice is 'Rock'), 'Rock' wins.

- If (user_choice is 'Rock' and device_choice is 'Paper') or (user_choice is 'Paper' and device_choice is


'Rock'), 'Paper' wins.

- If (user_choice is 'Scissors' and device_choice is 'Paper') or (user_choice is 'Paper' and device_choice


is 'Scissors'), 'Scissors' wins.
- Print the result of the round.

>>Announce the Winner:*

- If the user's choice matches the winning result, print "User Wins the game!!!".

- Otherwise, print "Device Wins The Game!!".

>>Play Again Prompt:*

- Ask the user if they want to play again.

- If the user inputs 'n' or 'N', break the loop and end the game.

- Otherwise, continue the loop for another round.

>> *End Game:*

- Print "Thanks For Playing. .

Flow chart
Start

Display "1. Rock, 2. Scissors, 3. Paper"

Prompt user for input (1-3)

Is input valid (1-3)?

/\
No Yes

| |

v v

Prompt user again Map user input to

until valid choice (Rock, Scissors, Paper)

Display user's choice

Generate random device choice (1-3)

Is device choice different from user choice?

/\

No Yes

| |

v v

Generate again Map device input to

until different choice (Rock, Scissors, Paper)

Display device's choice

Compare user choice and device choice


|

Determine the winner:

- Rock vs Scissors -> Rock wins

- Rock vs Paper -> Paper wins

- Scissors vs Paper -> Scissors wins

Display the round winner

Is user's choice the winner?

/\

Yes No

| |

v v

Display Display

"User Wins" "Device Wins"

Prompt for rematch (Y/N)

Is rematch 'N' or 'n'?

/\

Yes No
| |

v v

End Start over

Display "Thanks For Playing"

code
import random

while True:

print("1. Rock, 2. Scissors, 3. Paper")

user_input = int(input("Enter the number : "))

while user_input > 3 or user_input < 1 :

user_input = int(input("Please enter number between 1-3 : "))

if user_input == 1:

user_input_choice = 'Rock'

elif user_input ==2:

user_input_choice = 'Scissors'

else:

user_input_choice = 'Paper'
print("User has selected:- " , user_input_choice)

device_choice = random.randint(1,3) #randint says it should be a integer betwee 1-3

while user_input == device_choice:

device_choice = random.randint(1, 3)

if device_choice == 1:

device_input_choice = 'Rock'

elif device_choice ==2:

device_input_choice = 'Scissors'

else:

device_input_choice = 'Paper'

print("Device has selected:- ", device_input_choice)

if (user_input == 1 and device_choice == 2) or (user_input == 2 and device_choice == 1):

print("Rock Wins in this situation ! ")

result = 'Rock'

elif (user_input == 1 and device_choice == 3) or (user_input == 3 and device_choice == 1):

print("Paper Wins in this situation ! ")

result = 'Paper'

else:

print("Scissors wins in this situation ! ")


result = 'Scissors'

if user_input_choice == result:

print("User Wins the game!!!")

else:

print("Device Wins The Game!!")

print("\n")

print("Would you like to play again?")

print("-->Y for Yes else N for No")

rematch = input()

if rematch == 'n' or rematch == 'N' :

break

print("Thanks For Playing. . .")

You might also like