0
import keyboard
import time

s1 = 1
time.sleep(1)
while s1 < 100:
    keyboard.write(s1)
    s1 = s1 + 1

I can't write s1 because 1 is an int. But if I make it s1 = "1" then I can't do s1 < 100 because s1 is a string, so I need to write s1, but how?

1
  • keyboard.write(str(s1)) Commented Jul 25, 2022 at 23:03

2 Answers 2

2

You can use the int() or str() function where you need the value to be a string or int without reassigning it.

import keyboard
import time

s1=1
time.sleep(1)
while s1<100:
    keyboard.write(str(s1))
    s1=s1+1
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah the function is str(). Python doesn't know what string() is.
0

I think this is what you're trying to do here. I also changed the last line as it's simpler like that

import keyboard
import time

s1 = 1
time.sleep(1)
while s1 < 100:
    keyboard.write(str(s1))
    s1 += 1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.