How to realize number guessing Mini Program by Python
This article mainly introduces Python how to achieve number guessing Mini Program, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Guess the number Mini Game, constantly enter the number you guess (1-100), the program will remind you to adjust the size of the guess properly according to your input, until finally guess the random number''guessNumber = random.randint (1100) print ("I'm thinking a number between 1 and 100.") while True: print (' Take a guess.') Guess = int (input ()) if guess > guessNumber: print ("It's too high") elif guess < guessNumber: print ("It's to low") else: print ("Congratulations, you win.") Break
Result
Collatz sequence
Code
# Collatz sequence def collatz (number): if (number% 2 = = 0): return number / 2 else: return number * 3 + 1print ('Input a number.') while True: global number1 try: number1 = int (input () except ValueError: print (' Please input a number') continue if collatz (number1)! = 1: print (int (collatz (number1) Else: print (int (collatz (number1) break
Result
Thank you for reading this article carefully. I hope the article "how to achieve number guessing Mini Program with Python" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!