Get the App
SLTechnology News&Howtos  ›  Development  › 

How does python guess the numbers 1 to 10

Shulou Source: shulou.com Published: 2022-05-31 17:43:50 10月04日 Update

This article editor for you detailed introduction of "python how to guess numbers 1 to 10", the content is detailed, the steps are clear, the details are handled properly, I hope this "python how to guess numbers 1 to 10" article can help you solve doubts, following the editor's ideas slowly in depth, together to learn new knowledge.

Method description

1. The input number can be realized by the input () function, the comparison number can be realized by the conditional judgment sentence if, and the output result can be realized by the print () function.

2. If you need to make multiple comparisons, you need to use a for loop or a while loop.

Example

Import randomsecretnum = random.randint (1mai 10) count = 3print ("guessing number game, with numbers between 1 and 10) You have {0} chances. Format (count) while (count > 0): num = input ("enter a number:") if num.isdigit (): num = int (num) if num = = secretnum: print ("right") break elif num < secretnum: print ("smaller") else: print ("big") count-= 1 if count = = 0: print ("you don't have a chance") break print ("you still have {0} chances left" .format (count)) else: print ("you entered not a number Please re-enter ") print (" Game over ") to read here, this" how to guess numbers 1 to 10 "article has been introduced, want to master the knowledge of this article also need everyone to practice and use in order to understand, if you want to know more related articles, welcome to follow the industry information channel.

Tags: Numbers inputs can be passed articles opportunities content functions loops proper right between sentences examples ideas new knowledge methods more conditions steps knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia vpn Shulou Technology Microsoft