在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ 入門猜數(shù)字游戲哪里錯了呢?tries=tries+1沒用上!

入門猜數(shù)字游戲哪里錯了呢?tries=tries+1沒用上!

import random
secret = random.randint(1,100)
guess = 0
tries = 0

print( "AHOY! I'm the dread Pirate roberts, and I have a secret!")
print("It is a number from 1 to 99. I'll give you 6 tries.")

while guess !=secret and tries < 6:

guess = int(input("what's yer guess?"))
if guess < secret:
    print ("too low")
elif guess > secret:
    print("too high")
    
tries=tries+1
    
if guess == secret:
    print("down!")
else:
    print("no more")
    print("the secret was",secret)
回答
編輯回答
萌二代
import random
secret = random.randint(1,100)
print(secret)
guess = 0
tries = 6

print( "AHOY! I'm the dread Pirate roberts, and I have a secret!")
print("It is a number from 1 to 99. I'll give you 6 tries.")
for i in range(0,tries):
    #aa就是判斷你贏了沒  默認(rèn)為輸
    aa=False
    guess = int(input("what's yer guess?"))
    if guess < secret:
        print ("too low")
    elif guess > secret:
        print("too high")
    elif guess == secret:
        print("down!")
        #答對了,贏了
        aa=True
        #跳出循環(huán)
        break
if aa==True:
    print('Win')
else:
    print('Loser')

您可以試下循環(huán)

2017年3月13日 09:15