In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article "how to use Python to do a dice simulator and rock scissors paper game" the knowledge points of most people do not understand, so the editor summarized the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "how to use Python to do a dice simulator and rock scissors paper game" article.
I. Dice Simulator
Goal: make a program that can play dice games.
Tips: when asked by the user, use the random module to generate numbers between 1 and 6.
Second, rock scissors paper game
Goal: to make a command-line game in which players can choose between stone, scissors and paper and face off with the computer. If the player wins, the score will be added and the final score will be displayed to the player at the end of the game.
Tops: receive player selections and compare with computer selections. The selection of the computer is randomly selected in the list. If the player wins, it will be increased by one point.
Import randomchoices = ["Rock", "Paper", "Scissors"] computer = random.choice (choices) player = Falsecpu_score = 0while True: player = input ("Rock, Paper or Scissors?"). Capitalize () # judge the choice between the player and the computer if player = = computer: print ("Tie!") Elif player = "Rock": if computer = = "Paper": print ("You lose!", computer, "covers", player) cpu_score+=1 else: print ("You win!", player, "smashes", computer) player_score+=1 elif player = = "Paper": if computer = = "Scissors": print ("You lose!", computer, "cut" Player) cpu_score+=1 else: print ("You win!", player, "covers", computer) player_score+=1 elif player = = "Scissors": if computer = = "Rock": print ("You lose...", computer, "smashes", player) cpu_score+=1 else: print ("You win!", player, "cut" Computer) player_score+=1 elif player=='E': print ("Final Scores:") print (f "CPU: {cpu_score}") print (f "Plaer: {player_score}") break else: print ("That's not a valid play. Check your spelling! ") Computer = random.choice (choices) above is about "how to use Python to do a dice simulator and rock scissors paper game" the content of this article, I believe we all have a certain understanding, I hope the content shared by the editor will be helpful to you, if you want to know more about the relevant knowledge, please pay attention to the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.