Python rock paper scissor game (you vs computer)

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
no value
Seçkin Üye
Katılım
17 Nis 2020
Mesajlar
576
Çözümler
2
Tepki puanı
42
Ödüller
3
Yaş
24
6 HİZMET YILI
Hi guys, i saw ElSlayRR's post about his rock paper and scissors code in a very simple way. I've created this on my own, you could try run and play it. You can also set the score to win u want. I want to share my code to you. What are your thoughts about this? If you have a better idea share it to us, it would be great


Python:
import time
import random

run_again = "yes"
while run_again == "yes":
   boredGame = True
   compScore = 0
   userScore = 0
   print("Rock Paper Scissors vs Computer")
   print("Your opponent will be the Computer")
   score = int(input("How many scores to win? "))
   time.sleep(0.5)
   print("\nNOTE: No space before or/and after the word you have chosen")
   time.sleep(0.5)
   print("\nComputer:", compScore,"    ", "You:", userScore, "\n")
   while boredGame:
      print("rock")
      print("paper")
      print("scissor")
      user_weap = input("Choose your weapon: ")
      comp_weap = random.choice(["rock", "paper", "scissor"])
      if user_weap.lower() == "rock":
          if comp_weap == "paper":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("Computer Win")
              compScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if compScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                      exit()
              else:
                  print()
          elif comp_weap == "scissor":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("You Win")
              userScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if userScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                      exit()
              else:
                  print()
          else:
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("It's a Draw")
              print("\nComputer:", compScore,"    ", "You:", userScore, "\n")
      elif user_weap.lower() == "paper":
          if comp_weap == "scissor":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("Computer Win")
              compScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if compScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                      exit()
              else:
                  print()
          elif comp_weap == "rock":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("You Win")
              userScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if userScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                      exit()
              else:
                  print()
          else:
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("It's a Draw")
              print("\nComputer:", compScore,"    ", "You:", userScore, "\n")
      elif user_weap.lower() == "scissor":
          if comp_weap == "rock":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("Computer Win")
              compScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if compScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                     exit()
              else:
                  print()
          elif comp_weap == "paper":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("You Win")
              userScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if userScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                      exit()
              else:
                  print()
          else:
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("It's a Draw")
              print("\nComputer:", compScore,"    ", "You:", userScore, "\n")
 
Uzman Üye
Katılım
30 Ocak 2020
Mesajlar
299
Tepki puanı
25
Yaş
22
6 HİZMET YILI
Hi guys, i saw ElSlayRR's post about his rock paper and scissors code in a very simple way. I've created this on my own, you could try run and play it. You can also set the score to win u want. I want to share my code to you. What are your thoughts about this? If you have a better idea share it to us, it would be great


Python:
import time
import random

run_again = "yes"
while run_again == "yes":
   boredGame = True
   compScore = 0
   userScore = 0
   print("Rock Paper Scissors vs Computer")
   print("Your opponent will be the Computer")
   score = int(input("How many scores to win? "))
   time.sleep(0.5)
   print("\nNOTE: No space before or/and after the word you have chosen")
   time.sleep(0.5)
   print("\nComputer:", compScore,"    ", "You:", userScore, "\n")
   while boredGame:
      print("rock")
      print("paper")
      print("scissor")
      user_weap = input("Choose your weapon: ")
      comp_weap = random.choice(["rock", "paper", "scissor"])
      if user_weap.lower() == "rock":
          if comp_weap == "paper":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("Computer Win")
              compScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if compScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                      exit()
              else:
                  print()
          elif comp_weap == "scissor":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("You Win")
              userScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if userScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                      exit()
              else:
                  print()
          else:
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("It's a Draw")
              print("\nComputer:", compScore,"    ", "You:", userScore, "\n")
      elif user_weap.lower() == "paper":
          if comp_weap == "scissor":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("Computer Win")
              compScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if compScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                      exit()
              else:
                  print()
          elif comp_weap == "rock":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("You Win")
              userScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if userScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                      exit()
              else:
                  print()
          else:
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("It's a Draw")
              print("\nComputer:", compScore,"    ", "You:", userScore, "\n")
      elif user_weap.lower() == "scissor":
          if comp_weap == "rock":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("Computer Win")
              compScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if compScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                     exit()
              else:
                  print()
          elif comp_weap == "paper":
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("You Win")
              userScore += 1
              print("\nComputer:", compScore,"    ", "You:", userScore)
              if userScore == score:
                  game_run = str(input("Play the game again? yes/no: "))
                  if game_run == "yes":
                      compScore = 0
                      userScore = 0
                  else:
                      exit()
              else:
                  print()
          else:
              time.sleep(0.3)
              print("\nComputer:", comp_weap)
              print("You:", user_weap)
              print("It's a Draw")
              print("\nComputer:", compScore,"    ", "You:", userScore, "\n")
shall i run with copy paste
 
ég ríf ykkur í bita
Süper Üye
Katılım
15 Tem 2019
Mesajlar
756
Çözümler
3
Tepki puanı
91
Ödüller
6
6 HİZMET YILI
thank you bro:D
 
STALKER
Seçkin Üye
Katılım
14 Şub 2019
Mesajlar
301
Tepki puanı
10
Ödüller
3
7 HİZMET YILI
Maybe we could make the computer always win so the player is frustrated haha
 
Onaylı Üye
Katılım
9 Nis 2019
Mesajlar
50
Tepki puanı
0
Ödüller
4
Yaş
26
7 HİZMET YILI
Not a bad code. I think you can optimize something. I'll look for it now..
 
Seçkin Üye
Katılım
6 Haz 2020
Mesajlar
298
Çözümler
2
Tepki puanı
31
Ödüller
2
Yaş
26
5 HİZMET YILI
Your first Python game. Easy, right?
 
Uzman Üye
Katılım
20 Mar 2021
Mesajlar
280
Tepki puanı
16
Yaş
39
5 HİZMET YILI
You need add good 3d graphics for it and publich in Steam, it be better than 80% of other steam games lol )
 
Üye
Katılım
9 Haz 2017
Mesajlar
15
Tepki puanı
0
8 HİZMET YILI
Look like it has too many unnecessary lines it could be shorter and better.
 
a simple Russian man who helps people
Uzman Üye
Katılım
16 Ağu 2020
Mesajlar
195
Çözümler
2
Tepki puanı
8
Ödüller
5
Yaş
26
5 HİZMET YILI
thank you for the game code well done thank you for your efforts
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst