我正在對猜數字遊戲進行改進。玩家可以在第一輪後輸入自己的範圍。如何在下面的範圍中顯示輸入號碼?如何在句子中添加變量輸入?
print("Let's play again !" "I am thinking of a number between 1 and ")
我試過使用+,但它似乎只適用於單詞變量只。
下面是相關的部分代碼:
print ("Do you want to play again?" " Yes/No")
Play = input()
if Play.lower() == "yes":
print ("What do you want your range to be?" " 1-?")
import random
correctGuess = False
guessesTaken = 0
number = random.randint(1, int(input("Enter a number "))+1)
print("Let's play again !" "I am thinking of a number between 1 and ")
while correctGuess == False:
print("Take a guess.")
guess = input()
guess = int(guess)
guessesTaken = guessesTaken + 1
if guess < number:
print("Your guess is too low.")
if guess > number:
print("Your guess is too high.")
if guess == number:
correctGuess = True
guessesTaken = str(guessesTaken)
print("Congrats, " + myName + "! You guessed my number in " + guessesTaken + " guesses!")
else:
print ("Thanks for playing!" " Hope to see you soon!")
謝謝!