In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
The main content of this article is to explain "what is the method of Java to achieve the number guessing game", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the method of Java to realize the number guessing game"?
Import related modules
Import randomfrom datetime import datetime
Generate random numbers
Def random_number (): print ('*'* 30) print ('range of random numbers is 0,10') nb = random.choice ([x for x in range (11)]) return nb
Function introduction
Def intruduce (): print (this program has the following three functions: 1, start the game 2, view the bureau's historical data 3, exit the program') print ('* 30)
Guess the number
Def guess_number (nb): print (''the game begins! Warm reminder: the guess range is 10, you only have three chances, please cherish\ nguess') log = {} for i in range (3): try: guess_number = int (input ('enter guessed number:') except: print ('input error Please enter a valid number') continue if guess_number > 10: print ('the number entered is out of range') else: time = datetime.now () log [time] = guess_number if guess_number > nb: print ('\ n is not correct Elif guess_number = = nb: print ('\ nWow, you are really my little worm\ n') break else: print ('\ nNo, you underestimate me\ n') print (\ npublish the correct answer: {nb}\ n') return log
View the data entered by the Bureau
Def find_log (log): print ('the valid data entered by the Bureau is:\ n') if len (log): for xrecoy in log.items (): print (f' {x}: {y}') else: print ('empty')
Main program
If _ _ name__ = ='_ _ main__': choose_number = ['1' _ main__': choose_number ='1' '3'] log = {} while True: nb = random_number () intruduce () choose = input (' enter the serial number of the corresponding function:') if choose = = '1seam: log = guess_number (nb) if choose = =' 2seam: find_log (log) if choose = = '3seam: break If choose not in choose_number: print ('Please enter a valid number!') At this point, I believe you have a deeper understanding of "what is the method of Java to realize the number guessing game". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.