-1

I'm wanting to make s timer in python, were the user can type how much time they will wait for. The problem is that when the user inputs how much time they want to wait for, I don't know how to make that a variable. So far I have something like this:

n = input("How many seconds do you want to wait for?\n")



for countdown in range(n):
  time.sleep(1)
  print("...\n")
  print("You have successfully waited for " + n + " seconds.")

it makes n a string instead of a variable. Any ideas on how I could fix this?

3
  • n is a variable. The data type is a string Commented Mar 3, 2021 at 17:00
  • int is your friend. int('3') returns 3 Commented Mar 3, 2021 at 17:00
  • There's a difference between values and variables. What the user inputs is a value that's then bound to the variable n. It doesn't make sense to "convert a string into a variable" - values and variables are different things. Commented Mar 3, 2021 at 17:00

1 Answer 1

1

You've already set the variable n to the amount of seconds, however you need n to be an integer instead of a string. Try this:

n = int(input("How many seconds do you want to wait for?\n"))



for countdown in range(n):
  time.sleep(1)
  print("...\n")
print("You have successfully waited for " + str(n) + " seconds.")
Sign up to request clarification or add additional context in comments.

1 Comment

@ForceBru The last line should work now. n just needed to be converted to a string. Also, I un-indented it so that it won't print it until the end.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.