[PYTHON] Let's make a rock-paper-scissors game

It seems that Fuji Soba can be made in the neighborhood

What happened there before that? I tried to remember, but I couldn't remember at all

Dozens (hundreds of times?) Pass by, or from McDonald's across the street I should have seen it through the window, but I couldn't remember at all

When I go home and check it in Street View, Last year and two years ago, there was a curtain under construction. Even when I saw it, the impression that came out was "Is that so ...?"

I once again experienced that human memory is vague.

I can't remember it unless I'm aware of it,
If you are conscious of it, you can remember it, so
Studying is an act of consciousness and memorization.
Memorable is like storing toys in your head.
Play until later (=Think) It may lead to fun

Recently, I've been studying exclusively on the channel of Engineer Vtuber Rin.

https://youtu.be/JpcWUuG_5S0 It seems that you can enjoy learning when many people like this come out.

Let's make a rock-paper-scissors game

from random import randint
import time

hands = ["Goo", "Choki", "Paa"]
rules = ["Draw ", "Lose... ", "Win!!! "]
draw = 0
lose = 0
win = 0

print("----------------------------------------------")
print("      Let's JAN-KEN Start!!!!")
print("----------------------------------------------")

while True:
  # Player
  print("【 0 : Goo 】", "【 1 : Choki 】", "【 2 : Paa 】")

  while True:
    try:
        p = int(input("You choose ==========> "))
        if p in [0, 1, 2]:
          print("Yes!")
          break
        else:
          print("Say 0, 1 or 2! Thank you!") 
    except:
        print("Not even numbers! at least! Please use numbers at least!") 
  
  print("----------------------------------------------")
  print("■ You 【 " + hands[p] + " 】 play")
  time.sleep(0.9)
  #CPU
  m = randint(0, 2)
  print("● CPU 【 " + hands[m] + " 】 play")
  print("----------------------------------------------")
  time.sleep(0.9)
  #gameset
  i = (p - m) % 3
  print("■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■")
  print(rules[i])
  print("■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■")
  if i == 0:
      draw = draw + 1
  elif i == 1:
      lose = lose + 1
  else:
      win == win + 1
  time.sleep(0.9)
  #result
  print("{}...Win / {}...Lose / {}...Draw".format(win, lose, draw))
  print("■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■")
  if win == 3:
      print("▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼")
      time.sleep(3)
      print("3wins!!!! You win!!!!")
      print("▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲")
      break
  if lose == 3:
      print("▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼")
      time.sleep(3)
      print("3loses... You lose...")
      print("▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲")
      break
  time.sleep(1)

The above is slightly different from the content of the video,

  1. I wanted to make the output content a little flashy
  2. Since it was troublesome to convert to Japanese, I also made comments in English.
  3. I wanted to add error handling when I entered ** other than 0,1,2 **

First of all, I drew a flow diagram for error handling when inputting other than 0, 1, 2

janken_flow.drawio_PNG.png

In making the flow chart, I realized the ease of use of this site. https://app.diagrams.net/

And here is the added while statement

while True:
    try:
        p = int(input("You choose ==========> "))
        if p in [0, 1, 2]:
          print("Yes!")
          break
        else:
          print("Say 0, 1 or 2! Thank you!") 
    except:
        print("Not even numbers! at least! Please use numbers at least!") 

I got the intended result There may be a smarter way to write it, but for now it looks like this

For study results

The above is part of last year's study,

  1. Write a flow chart
  2. Write exception handling
  3. Write your own while statement

I was happy to be able to say that, and I remembered it. I wrote it here as well

New Year's aspirations (?)

While the people around me are doing high-level processing, I'm still wondering if it's around here, but I'm going to proceed at my own pace

Also, these days I get sleepy as soon as I eat, I'm getting fat again, so I'll review my diet

Recommended Posts

Let's make a rock-paper-scissors game
Make a squash game
Let's make a shiritori game with Python
Make a Tetris-style game!
Make a rock-paper-scissors game in one line (python)
Let's make a Discord Bot.
Let's make a remote rumba [Hardware]
Let's make a remote rumba [Software]
Let's make a breakout with wxPython
Let's make a spot sale service 1
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Let's make a spot sale service 3
Let's make a number guessing game in your own language!
Let's make a voice slowly with Python
Let's make a simple language with PLY 1
Let's make a web framework with Python! (1)
Let's make a tic-tac-toe AI with Pylearn 2
Let's make a combination calculation in Python
Let's analyze a Chinese retro game machine
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
Let's make a Backend plugin for Errbot
[Python] Make a game with Pyxel-Use an editor-
I want to make a game with Python
Make a cocos2d game in a pixel double window
[Python] Make a simple maze game with Pyxel
Let's replace UWSC with Python (5) Let's make a Robot
Let's make a module for Python using SWIG
I tried to make a ○ ✕ game using TensorFlow
〇✕ I made a game
Make a function decorator
I'll make a password!
Make a Nyan button
Make a Base64 decoder
Let's make a spot sale service 9 (Task Queue edition)
Let's make a Makefile and build it (super beginner)
[Let's play with Python] Make a household account book
How to make a shooting game with toio (Part 1)
Let's make dependency management with pip a little easier
[For play] Let's make Yubaba a LINE Bot (Python)
Let's make a Mac app with Tkinter and py2app
Let's make a spherical grid with Rhinoceros / Grasshopper / GHPython
Let's make a spot sale service 8 (image uploader edition)
[Super easy] Let's make a LINE BOT with Python.
Let's easily make a math gif using Google Colaboratory
Let's make a cron program in Java! !! (Task Scheduler)
Let's make a websocket client with Python. (Access token authentication)
Make a Blueqat backend ~ Part 1
Nostalgic, let's reproduce a character game like CBM-3032 with ncursesw.
Yes, let's make a Minecraft server (Oracle Linux + Spigot + Geyser)
How to make a multiplayer online action game on Slack
Let's make Othello with wxPython
Let's make a robot that solves the Rubik's Cube! 2 Algorithm
Let's make an Errbot plugin
Let's make a spot sale service 4 (in Python mini Hack-a-thon)
How to make a simple Flappy Bird game with pygame
[Django] Make a pull-down menu
Let's try a shell script
Make a LINE BOT (chat)
Let's make Splatoon AI! part.1