In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to use random random numbers to develop guessing games in Python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
1. Random number module random
To use random integers, you need to import from random import randint using a random number class
Functions of random integers
Randint (start value, end value) returns a random integer between the start value and the end value.
For example:
X=randint (1100) # x is a random integer between 1 and 100
Second, the case: the idea of guessing numbers.
1. Randomly generate a random integer x
2. While endless cycle, the function is to make guesses constantly
3. Note that the value entered by the input function returns a string type. If you want to make a numerical comparison, you must convert the numeric type.
III. Supplementary comparison of multiple conditions
If the value of t 100 # t is less than 1, or t is greater than 100, then the result is True
If tweak 50, then 50100 is false
False or false result is false
Or's conclusion: before and after the judgment of or, as long as there is one true true, the result is true true.
And's conclusion: before and after the judgment of and, as long as one is a false false, the result is a false false.
IV. Summary and emphasis
1. Master the import of random number module
2. Master the use of random number function
3. Note that the input input returns string.
4. the conclusion of multi-conditional judgment.
5. Learn to use help (random.randint) to view help
The knowledge source code of this section:
From random import randint
X=randint (1100) print ("the system has generated a random number between 1 and 100, please guess!") while True: a=input ("") t=int (a) if T100: print ("Please output a number between 1 and 100") continue if t > x: print ("guess big, please continue to guess!") Elif t
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.