簡體   English   中英

我在 python 2.7 中有一個錯誤,不知道如何修復它

[英]I have an error in python 2.7 and dont know how to fix it

我的錯誤是:

File "guessing_game.py", line 117, in <module>               
    game()                               
  File "guessing_game.py", line 78, in game              
    for guesses in range (0,NUMBER_OF_GUESSES):          
TypeError: 'int' object is not callable     

我的代碼:(順便說一句,在我的電腦上,函數中的所有內容都有一個額外的縮進,我的代碼只是復制和粘貼錯誤)

import time
#It clears all the code you have left in the terminal
import os
os.system("clear")

def game():



#Import the random module so it can create the random number
import random
MIN_DESIRED_NUMBER = 100
print "what range of numbers do you want to guess in (keep in mind you need a minimum of 100 numbers to guess from and you only get a maximum of 20 guesses)"
range = input()
range = int(range)
DESIRED_NUMBER = int(range)
while DESIRED_NUMBER < MIN_DESIRED_NUMBER:
    print "Your desired number to guess from is to low"
    print "Please choose another Number that is bigger 100 or bigger"
    range = input()
    range = int(range)
    DESIRED_NUMBER = int(range)

if DESIRED_NUMBER > MIN_DESIRED_NUMBER:

#Generate the random number and store it
    answer = random.randint(0,DESIRED_NUMBER)


#Set number of guess's





MAX_GUESS = 20


#set winner to false
winner = 0


print "The aim of the game is to guess a number between 1 and %s. How many guess would you like to have? (you are only allowed a maximum of 20 guesses)" % (DESIRED_NUMBER)
number = input()
number = int(number)
NUMBER_OF_GUESSES = int(number)
while NUMBER_OF_GUESSES > MAX_GUESS:
    print "Your desired number of guesses is to high"
    print "Please choose another Number that is 20 or less"
    number = input()
    number = int(number)
    NUMBER_OF_GUESSES = int(number)

if NUMBER_OF_GUESSES < MAX_GUESS:



#Print Completed instructions 

        print "You will now only have %s guesses to guess your number" % (NUMBER_OF_GUESSES)


    #Start the number loop of tries left
NUMBER_OF_GUESSES = int(number)
for I in range (0,NUMBER_OF_GUESSES):
    #Ask for number
    print "Please enter your guess"

    #Recive number and say if the number is hight or lower

    guess = input()
    #This converts guess from the text into an integer and the stores it again
    guess = int(guess)
    if guess > answer:
        print "Your number is to high"
    elif guess < answer:    
        print "Your answer is to low" 
    elif guess == answer:
        print "YAY YOU GOT THE ANSWER"
        winner = 1
        break


    #Stop loop if number is correct


#Say that the number was 
if winner == 0:
    print "You have used all of your guesses"
print "The number was %s" % (answer)


print "would you like to play again? (0/1)"
redo = int(input())
if redo == 1:
    game()
    os.system("clear")
elif redo==0:
    print "alright bye!!!"
time.sleep(3)
os.system("clear")

游戲()

您已通過將其用作變量名稱來覆蓋名稱range 不要那樣做。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM