좋아요, 수업을위한 프로젝트를 진행하고 있는데,이 논리 오류가 붙어 있습니다. 필자는 코드에서 오류를 수정 한 후에 원래 오류의 나머지 부분을 지적했다 ... 그리고 나는 논리 오류가 어디 있는지 알고있다. 나는 그것을 고치는 방법을 확신 할 수 없다. 도움을받을 수 있을까요?python 3 논리 오류로 인해 모두 엉망이되었습니다.
미리 감사드립니다.
import random
def display_title():
print("Guess the number!")
print()
def set_limit():
print("Enter the upper limit for the range of numbers: ")
limit = int(input())
return limit
def count(): ## had to add count being defined as below it was unrecognized by python.
count +=1
def play_game(limit):
global count
number = random.randint(1, limit)
print("I'm thinking of a number from 1 to " + str(limit) + "\n")
while True:
guess = int(input("Your guess: "))
if guess < number:
print("Too low. ")
count ## See def count
elif guess >= number:
print("Too high. ")
count ## See def count
elif guess == number: ## Pretty sure my logic error is here <----
print("You guessed it in " + str(count) + " tries.\n")
return
def main(): ## syntax error, no : was here
display_title()
again = "y"
while again.lower() == "y":
limit = set_limit()
play_game(limit) ## limit wasn't set inside, causing a missing positional argument
again = input("Play again? (y/n): ")
print()
print("Bye!")
if __name__ == "__main__":
main()
도움과 설명에 너무 감사드립니다 !!! –