Sample code for python to realize human and computer guessing.
Complete the development of an interactive human-computer guessing game, where the user implements the punches through console inputs and the computer implements the punches through random numbers in the program, and outputs the results at the end of each round. The game is stopped when the user inputs n and the total result is output.
import random all = ['Stone','Scissors','Boo'] computer = (['Stone','Scissors','Boo']) #All winnings win = [['Stone','Scissors'],['Boo','Stone'],['Scissors','Boo']] class Text(): def func_play(self): ind = input('Please enter [0] rock [1] scissors [2] cloth') if (): try: raise ValueError('Please enter a number') except ValueError as v: print(v) elif (): ind = int(ind) if 0<=ind<=2: play = all[ind] print('You type %s, the computer types %s'%(play,computer)) if play == computer: = 'Tie game' elif [play, computer] in win: = 'You win' else: = 'You lost' else: print('Please enter a number between 0 and 2') print() def write_file(self): with open('','a',encoding='utf-8') as f: (+'\n') while True: t = Text() t.func_play() t.write_file()
to this article on the python implementation of human and computer guessing sample code is introduced to this article, more related python human and computer guessing content please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!
Related articles
Python read data in excel file, plot line graphs and scatter plots
This article introduces the Python read excel file data, drawing line graphs and scatterplots, the article around the theme to develop a detailed introduction, with certain reference value, the need for partners can refer to it!2022-09-09python implementation of grammatical left-recursive elimination
This article introduces python to achieve the elimination of grammatical left-recursive method, this article through the example code to give you a very detailed, for everyone to learn or work with a certain reference value, the need for friends can refer to the next!2020-05-05Python implementation of counting and bucket sort example code
This article introduces the python counting sorting and bucket sorting, the text through the sample code is very detailed, for everyone's learning or work with certain reference learning value, the need for friends below with the editor to learn together!2019-03-03Usage of Python closures
This article mainly introduces the use of Python closures, when the return of the internal function uses the variables of the external function on the formation of closures, the following more related to the content of the need for partners can refer to it2022-04-04pyqt5 login interface using pyqtDesigner
This article is mainly for you to introduce in detail the pyqt5 use pyqtDesigner to realize the login interface, with certain reference value, interested partners can refer to it!2019-03-03Ways to plot and output an image to a file using Python Matplotlib
This article introduces the use of Python Matplotlib plotting and output images to the file in the way, with good reference value, I hope you can help, if there is any error or not fully consider the place, I hope not to give advice!2023-09-09Example analysis of local variable usage in python functions
This article introduces the python function of local variable usage, a more detailed analysis of the principle of Python local variables and the use of skills, and a comparative analysis of the local variables and global global variable usage differences, with certain reference value, you can refer to the following2015-08-08Pandas method of counting values inside duplicate columns
Today, I'd like to share a Pandas statistics duplicate the value of the column inside the method, has a good reference value, I hope to help you. Together follow the editor over to see it2019-01-01Python based implementation of flipping images using Pygame
This article introduces the use of Python based Pygame to flip the image, we will learn how to use Pygame to flip the image, to flip the image, we need to use (Surface, xbool, ybool) method, the method is called according to our needs in the vertical or horizontal direction of the image to flip the image, the following to look at the specific implementation of the process of it!2022-02-02Installing PaddlePaddle locallyInstallation guide and step-by-step details
PaddlePaddle is an open source and open deep learning platform developed by Baidu, with a comprehensive range of officially supported industrial-grade application models, covering a variety of areas such as natural language processing, computer vision, recommendation engines, and open a number of leading pre-trained Chinese models. This article introduces the local installation of PaddlePaddle installation guide, friends who need it can refer to the following2021-12-12