-3

I am attempting to write a bot to preform automated actions on Discord. I have written the following code to do so:

import clipboard
import time

numnum = input("  What do you want the delay from each next number? (in seconds) \n\t    Please type it here:    ")
startingnum = input("   What do you want the starting number to be? \n\t    Please type it here:    ")
for i in range startingnum , 99999999999999):
    print('Your clip Board is set to ' + i )
    clipboard.copy(i)
    time.sleep(numnum)
print('terminal will close in 5 seconds')
time.sleep(5)

However, this code generates the following error:

TypeError: can only concatenate str (not "int") to str

I am not sure why this error occurs, could someone give me insight into why this error happens in my code?

Xiddoc
  • 3,369
  • 3
  • 11
  • 37
Oasis
  • 3
  • 1
  • `TypeError: can only concatenate str (not "int") to str` could you please explain what particular word don't you understand in this sentence? – NobbyNobbs Mar 14 '21 at 20:29
  • please remove the unnecessary sentences of your question. and clearly tell where the error occurred – Towsif Ahamed Labib Mar 14 '21 at 20:38
  • What do you not understand from the many references you found when you looked up your error message on line? See [How much research](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) and the [Question Checklist](https://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist) – Prune Mar 14 '21 at 20:45

4 Answers4

0

This is a pretty straight forward syntax problem You are trying to concatenate a string 'Your clip Board...' and an integer i

In order to concatenate correctly, typecast the integer to a string.

for i in range (startingnum , 100):
    #typecast int --> str using the built in str() function
    print('Your clip Board is set to ' + str(i) ) 
Blakedallen
  • 664
  • 1
  • 8
  • 23
0

Convert i to a string

import clipboard
import time

numnum = input("  What do you want the delay from each next number? (in seconds) \n\t    Please type it here:    ")
startingnum = input("   What do you want the starting number to be? \n\t    Please type it here:    ")
for i in range startingnum , 99999999999999):
    print('Your clip Board is set to ' + str(i) )
    clipboard.copy(i)
    time.sleep(numnum)
print('terminal will close in 5 seconds')
time.sleep(5)
Johnson
  • 144
  • 8
0

Here are the 2 changes you need to make:

  1. As you are requesting for user input, numnum and startingnum will store string values and not int values. So use int(input(...)) for an integer type input.
  2. When you are combining string and int, use a comma(,) instead of +.

Here is the code snippet:

import clipboard
import time

numnum = int(input("  What do you want the delay from each next number? (in seconds) \n\t    Please type it here:    ")) #Change 1
startingnum = int(input("   What do you want the starting number to be? \n\t    Please type it here:    "))
for i in range(startingnum , 99999999999999):
    print('Your clip Board is set to ' , i ) #Change2
    clipboard.copy(i)
    time.sleep(numnum)
print('terminal will close in 5 seconds')
time.sleep(5)
Dharman
  • 30,962
  • 25
  • 85
  • 135
Prajwal
  • 57
  • 7
0
numnum = input("  What do you want the delay from each next number? (in seconds) \n\t    Please type it here:    ")
startingnum = input("   What do you want the starting number to be? \n\t Please type it here:    ")
for i in range (startingnum , 99999999999999):
    print('Your clip Board is set to ' + str(i) )
    clipboard.copy(i)
    time.sleep(numnum)
print('terminal will close in 5 seconds')
time.sleep(5)