2014-11-02 65 views
-2

我在python中編程。我試圖讓用戶猜一個數字,我相信我有正確的代碼1和100之間,但我不斷收到各地語法錯誤「而」while while循環同時生成一個隨機數的Python語法錯誤

import random 

def guessthenumber(): 
    print("Welcome user. In this game, you must correctly guess a randomly generated number between 1 and 100.") 

    guessamount = 1 
    randomnumber = random.randrange(1, 100) 

    numberguess = int(input("Please enter your guess") 

    while numberguess != numbertoguess: 
     if numberguess < numbertoguess: 
      print("You must guess higher.") 
     elif numberguess > numbertoguess: 
      print("You must guess lower.") 
     guessamount += 1 
    print("You have correctly guessed the number! It took you {} guesses".format(guessamount)) 

截圖:

+1

youre在那裏你要求輸入 – 2014-11-02 12:14:55

回答

0

你只是缺少一個括號:

numberguess = int(input("Please enter your guess")) 
0

猜數字= INT(輸入( 「請輸入您的猜想」)

你錯過了)在年底關閉INT()部分...

+0

行的末尾缺少),我改變了一些東西。剛剛刪除了一個說numbertoguess = int(隨機數)的東西。我會改回它。無論如何,thansk傢伙! – Harnell 2014-11-02 12:19:28

+0

非常歡迎您...如果您需要幫助python,我會盡力幫助您:) – 2014-11-02 12:22:06