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