1 inport random 2 secret = random.randint(1, 99) 3 guess = 0 4 tries = 0 5 print "AHOY! I'm the Dread pirate Roberts, and i have a cecret!“ 6 print ”It is a number from 1 to 99. I'll give you 6 tries. " 7 while guess != secret and tries < 6: 8 guess = input("what's yer guess? “) 9 if guess < secret: 10 print "Too low, ye scurvy cog!” 11 elif guess > secret: 12 print "Too high, landluber!" 13 14 tries = tries + 1 15 16 if guess -- secret: 17 print "Avast! Ye got it! pound my secret, ye did!" 18 else: 19 print "No more guesses! Better luck next time,matey!" 20 print "The secret number was“, secret
import
还是不行呢!
import random secret = random.randint(1, 99) guess = 0 tries = 0 print "AHOY! I'm the Dread pirate Roberts, and i have a cecret!“ print ”It is a number from 1 to 99. I'll give you 6 tries. " while guess != secret and tries < 6: guess = input("what's yer guess? “) if guess < secret: print "Too low, ye scurvy cog!” elif guess > secret: print "Too high, landluber!" tries = tries + 1 if guess -- secret: print "Avast! Ye got it! pound my secret, ye did!" else: print "No more guesses! Better luck next time,matey!" print "The secret number was“, secret
python3输出语句也不对、print()
@初新晓: 大神可以用Python3编写一个猜数游戏给我参考一下吗?我改了还是不行呢!
import random secret = random.randint(1, 99) guess = 0 tries = 0 print("AHOY! I'm the Dread pirate Roberts, and i have a cecret!“) print(”It is a number from 1 to 99. I'll give you 6 tries. ") while guess != secret and tries < 6: guess = input("what's yer guess? “) if guess < secret: print("Too low, ye scurvy cog!”) elif guess > secret: print("Too high, landluber!") tries = tries + 1 if guess -- secret: print("Avast! Ye got it! pound my secret, ye did!") else: print("No more guesses! Better luck next time,matey!") print("The secret number was“, secret)
@Miraclexu 你双引号一眼看去就有错、那里报错就改那里、报错写的很清楚的
@初新晓: 谢谢!