さて、私はクラスのプロジェクトに取り組んでいますが、私はこの論理エラーに固執しています。私は私のコードでそれらを修正した後、元のエラーの残りの部分を指摘した...と私は論理エラーがどこにあるか知っているように感じる。私はちょうどそれを修正する方法が不明です。助けてもらえますか?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()
本当にありがとうございました! –