程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python: guessing numbers game

編輯:Python

1 introduction

Python The classic number guessing game , Almost everyone can do it when they learn programming , It is also a small way of entertainment .

2 Problem description

Example : The computer randomly generates 1-100 Integer between , Let users guess , When you guess wrong , You will be prompted to guess

Is the number big or small , Until the user guesses right , The game is over .

Input : The first line of input gives a value that does not exceed 100 The positive integer , This number is randomly generated by the game

A number ; Then let the user enter a number .

Output : The user input number and random number are output at the same time “ Congratulations on your guesses !”

3 Algorithm description

The number guessing game is to make the computer randomly generate a 100 Integer within , The user enters a number to guess it , And prompt ‘Too Big’ perhaps ‘Too Small’, Equality means you have guessed . If you guess , Then end the program .

4 Conclusion

The game uses the knowledge of loop statements and conditional statements . For starters , Give it a good knock , Can consolidate the knowledge in this field .


The attachment

import random
number=random.randint(1,100)
while True:
guess=int(input(‘ Please enter 100 Integer within :’))
if guess > number:
Print(‘Too Big’)
if guess < number:
print(‘Too Small’)
else:
Print(‘ Congratulations on your guesses !’)
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved