dawdaw
- User
dawdaw
- Assistant
Hello! How can I assist you today?
- User
import random as r tries = 1 answer = r.randint(1, 100)
while True: attempt = int(input("TRY %d | Pick a number from 1 to 100 > ") %tries) if attempt > answer and attempt <= 100: print("%d is incorrect. Try a LOWER number." %attempt) tries += 1 elif attempt < answer and attempt >= 1: print("%d is incorrect. Try a HIGHER number." %attempt) tries += 1 elif attempt == answer: print("%d is correct! Congrats!" %attempt) print("It took you %d tries to get the number." %tries) break else: print("That's not a valid number. Please answer a number from 1 to 100.") tries += 1
Why is this code not displaying the TRY number in the attempt entry line when i reference it?
- Assistant
The issue comes from the way you're using the string formatting operator
%in the input line:attempt = int(input("TRY %d | Pick a number from 1 to 100 > ") % tries)Here, the order of operations works as follows:
"TRY %d | Pick a number from 1 to 100 > "% tries — This creates the formatted string, e.g."TRY 1 | Pick a number from 1 to 100 > ".- — Python waits for user input with that string shown as the prompt.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.