Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report