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

Learn Python editing guessing numbers games

編輯:Python

import random # Random number module
num=random.randint(1,100) # Pick an integer at random for us to use
print(f' Tips : The correct number is {num}')
print('*'*30,' Guess number games ','*'*30)
print(' The rules of the game : If you guess right, you'll get 100 million dollars , Guess the range 1-100 Between , Please start !')

a=3 # Conditions for ending the cycle , Three opportunities
while a>0:
    a-=1
    number=int(input(' Please enter the number you want to guess :'))
    if number<0 or number>100:
        print(f' The number you entered is not within the specified range , You have {a} Second chance ')
    elif number<num:
        print(f' Your guess is small , You have {a} Second chance ')
    elif number>num:
        print(f' Your guess is too big , You have {a} Second chance ')
    else:
        print(' Congratulations on your guesses , Reward 1 Billion dollars !!!')
        print(' Game over ')
        break
    if a==0: # Add another if Sentence judgment , Used to reset the number of times
        print(' The opportunity has run out , Want to play again ')
        key=input(' Please enter q Enter refresh times , Or enter another to end the game :')
        if key =='q':
            a=3
        else:
            print(f' The number of times has been used up , Challenge failure indication ! Tips : The correct number is {num}, Do it all over again !')
            break


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved