Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use python function to realize the effect of rock scissors and paper

Shulou Source: shulou.com Published: 2022-06-03 05:56:41 10月03日 Update

This article mainly introduces "how to use the python function to achieve the rock scissors paper effect". In the daily operation, I believe that many people have doubts about how to use the python function to achieve the stone scissors paper effect. The editor consulted all kinds of data and sorted out a simple and easy-to-use method of operation. I hope it will be helpful for everyone to answer the doubt of "how to use the python function to achieve the stone scissors paper effect". Next, please follow the editor to study!

Problem description

Example: "stone", "scissors" and "paper" are believed to be a simple and quick way to solve problems used by everyone in their childhood, such as: "who is going to take out the trash today?"emmm, I don't want to go" coincidentally, I don't want to, then we have stone scissors cloth trumpet! whoever loses will go. There is no denying that this kind of fist guessing helps us solve a lot of problems, so, do you know how to use a simple python function to achieve rock scissors paper?

Input: stone, scissors, paper

Output: lost, won, draw

Solution

Import random

Number = 1

Yin_number= 0

Shu_number = 0

While number 2:

Print) Please pay attention to the rules of the game! Cannot give more than 2 numbers')

Else:

Data = ['stone', 'scissors', 'paper']

Com = random.randint (0,2)

Print ("you send {}, I send {}" .format (data [user], DataCom))

If user = = com:

Print ('draw')

Continue

Elif (user = = 0 and com = = 1) or (user = = 1 and com = = 2) or (user = = 2 and com = = 0):

Print ('Congratulations, you won')

Yin_number + = 1

Else:

Print ('Sorry, you lost')

Shu_number + = 1

Num + = 1

At this point, the study on "how to use the python function to achieve the rock scissors paper effect" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Stone knife paper function effect scissors problem study representative draw more help utility regret next brother method garbage number article way Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS OPPO Reno Shulou Information Microsoft Huawei