Python study notes _005

This is the code I wrote before reading the sample code.

--Point --There are the following methods to compare character strings. --Exact match (equivalent): ==,! = --Partial match: in, not in --Start with (), ends with (): Start with (), ends with () --If there are multiple conditions (and or, etc.) in the if condition, you can use a backslash () to start a new line as many times as you like. Similarly, you can start a new line as many times as you like within the parentheses (). There is no indentation limit.

sample03.py


import random

#Definition of rock-paper-scissors
choices = ['Goo', 'Par', 'Choki']

str_gu = "Goo"
str_pa = "Par"
str_chyoki = "Choki"

icon_gu = "✊"
icon_pa = "✋"
icon_chyoki = "✌️"

people_win = "People win"
computer_win = "PC wins"

#Make a PC selection
computer_choice = random.choice(choices)

#Listen to people's choices
people_choice = input("What is your choice? Please select one from "Goo, Par, Choki".")

#When a person inputs only a part:
if (people_choice.startswith("g") or
    people_choice.startswith("Gu") or
    people_choice.startswith("Gu") ) :
    people_choice = str_gu

if (people_choice.startswith("p") or
    people_choice.startswith("Pa") or
    people_choice.startswith("Pacific League") ) :
    people_choice = str_pa

if (people_choice.startswith("c") or
    people_choice.startswith("Chi") or
    people_choice.startswith("Ji")) :
    people_choice = str_chyoki
    

#Set icon
computer_icon = ""
people_icon = ""
if computer_choice == str_gu :
    computer_icon = icon_gu
elif computer_choice == str_pa :
    computer_icon = icon_pa
elif computer_choice == str_chyoki :
    computer_icon = icon_chyoki

if people_choice == str_gu :
    people_icon = icon_gu
elif people_choice == str_pa :
    people_icon = icon_pa
elif people_choice == str_chyoki :
    people_icon = icon_chyoki

#Output PC selection
if people_icon == "" :
    print("I made a mistake. Please try again from the beginning.")
    
#Output PC selection
print("The choice of computer",
      computer_choice,
      computer_icon)
print("The choice of person",
      people_choice,
      people_icon)

#Judgment
# 1.If they match
if computer_choice == people_choice :
    print("Please play rock-paper-scissors again.")
elif computer_choice == str_gu and people_choice == str_pa :
    print(people_win)
elif computer_choice == str_pa and people_choice == str_chyoki :
    print(people_win)
elif computer_choice == str_chyoki and people_choice == str_gu :
    print(people_win)
else :
    print(computer_win)

Recommended Posts

Python study notes _000
Python study notes_006
Python study notes _005
Python study notes_001
Python study note_002
Python scraping notes
Python learning notes
Jupyter study notes_006
Python beginner notes
python C ++ notes
Python study note_003
Python grammar notes
Python Library notes
Jupyter study notes_008
python personal notes
Jupyter study notes_004
Jupyter study notes_001
python pandas notes
python learning notes
Python3.4 installation notes
Python study day 1
missingintegers python personal notes
Python package development notes
python decorator usage notes
Python ipaddress package notes
[Personal notes] Python, Django
Python Pickle format notes
First Python miscellaneous notes
Matlab => Python migration notes
Notes around Python3 assignments
Notes using Python subprocesses
Python try / except notes
Python framework bottle notes
Python notes using perl-ternary operator
O'Reilly python3 Primer Learning Notes
Web scraping notes in python3
Python
Python standard unittest usage notes
Python notes to forget soon
python * args, ** kwargs Usage notes
Study Python with Google Colaboratory
Python notes using perl-special variables
Python 處 處 regular expression Notes
Python Tkinter notes (for myself)
Study from Python Hour4: Object-oriented ②
[Python] Notes on data analysis
Python data analysis learning notes
Notes on installing Python on Mac
python pandas study recent summary
[WIP] Fluent Python Study Note
Study from Python Hour4: Object-oriented ①
New Linux textbook (study notes)
Get Evernote notes in Python
Notes on installing Python on CentOS
Notes on Python and dictionary types
Minimum grammar notes for writing Python
selenium case study summary python pyCharm
Study from Python Hour2: Control statements
Personal notes for python image processing
Python Pandas Data Preprocessing Personal Notes
Typing automation notes by Python beginners