Quote (Helic @ Mar 13 2024 02:08am)
Based on the comments in the code, it smells like ChatGPT.
Probably,
So many using it, not knowing it often causes more issues then helping.
ChatGPT is a decent tool to use as references if you already know coding etc.
Actually copied the msg from terp
ChatGpt:
Code
def guess_number():
print("Welcome to the Number Guessing Game!")
print("Think of a number between 1 and 100, and I'll try to guess it in 7 attempts or less.")
input("Press Enter when you're ready...")
low = 1
high = 100
attempts = 0
while True:
guess = (low + high) // 2
attempts += 1
print(f"My guess is {guess}.")
response = input("Is it correct? (yes/no): ").lower()
if response == "yes":
print(f"Hooray! I guessed your number ({guess}) in {attempts} attempts!")
break
elif response == "no":
attempts_left = 7 - attempts
if attempts_left == 0:
print("Oops! I've run out of attempts. Better luck next time!")
break
else:
print(f"Okay, is your number higher or lower than {guess}?")
direction = input("Type 'higher' or 'lower': ").lower()
if direction == "higher":
low = guess + 1
elif direction == "lower":
high = guess - 1
else:
print("Invalid input. Please type 'higher' or 'lower'.")
if __name__ == "__main__":
guess_number()
And CoPilot
Code
import random
def guess_number():
# Generate a random number between 1 and 100
num = random.randint(1, 100)
print("Think of a number between 1 and 100. I'll try to guess it!")
# Initialize the search range
lower_bound, upper_bound = 1, 100
# Set the maximum number of guesses
max_guesses = 10
for attempt in range(max_guesses):
# Make a guess
guess = (lower_bound + upper_bound) // 2
print(f"My guess is {guess}.")
# Ask for feedback
response = input("Is my guess correct? (yes/no): ").strip().lower()
if response == "yes":
print(f"I guessed it! Your number is {guess}.")
break
elif response == "no":
# Adjust the search range based on feedback
if guess < num:
lower_bound = guess + 1
else:
upper_bound = guess - 1
else:
print("Please answer with 'yes' or 'no'.")
else:
print(f"Oops! I couldn't guess your number in {max_guesses} tries. It was {num}.")
# Call the function to play the game
guess_number()
And this was with you's ai
Code
import random
def guess_number():
low = 1
high = 100
attempts = 0
guess = 50
while attempts < 7:
print(f"My guess is {guess}.")
response = input("Is it correct? (yes, higher, lower): ").lower()
if response == "yes":
print("I guessed it right! Thanks for playing.")
return
elif response == "higher":
low = guess + 1
guess = (low + high) // 2
elif response == "lower":
high = guess - 1
guess = (low + high) // 2
else:
print("Invalid input. Please enter 'yes', 'higher', or 'lower'.")
attempts += 1
print("I couldn't guess the number in 7 attempts. Maybe next time!")
return
number_to_guess = random.randint(1, 100)
print("Welcome to the number guessing game!")
print("Pick a number between 1 and 100 in your mind and let's see if I can guess it.")
print("Please provide feedback with 'yes', 'higher', or 'lower'.")
guess_number()