-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?

  • `n` *is* a variable. The data type is a string – Wondercricket Mar 03 '21 at 17:00
  • `int` is your friend. `int('3')` returns `3` – dawg Mar 03 '21 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. – ForceBru Mar 03 '21 at 17:00

1 Answers1

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.")
Illusion705
  • 451
  • 3
  • 13
  • @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. – Illusion705 Mar 03 '21 at 17:09