Counting Characters in a varible python
<p>i am trying to create a program to print a line of text a certain amount of times, i want to limit the amount of letters in the first text entry and i cant figure out how.</p>

<p>code: </p>

<pre><code># Hello World Script 2.0

import random
**------------------------------------------------
#i want to limit the amount of characters, how?
------------------------------------------------**
print("What do you want to be printed?(Max 20 Characters)")
var0 = input("&gt; ")

print("Please enter the amount of times you want that printed(max 100000)")
print('Or enter "R" for a random number')
var2 = input("&gt; ")

if int(var2) &gt; 100000:
    print("That number is too high, please restart the proram and enter something smaller.")
    exit()

if var2 == "r":
    var2 = random.randint(1,100000)


var1 = var0 * int(var2)
print(var1, var2)
</code></pre>

<p>You could check the length of the string with the function len().</p>

<pre><code>import random
**------------------------------------------------
#i want to limit the amount of characters, how?
------------------------------------------------**
print("What do you want to be printed?(Max 20 Characters)")
var0 = input("&gt; ")

if len(var0) &gt; 20:
   print("That is too long")
   exit()

print("Please enter the amount of times you want that printed(max 100000)")
print('Or enter "R" for a random number')
var2 = input("&gt; ")

if int(var2) &gt; 100000:
    print("That number is too high, please restart the proram and enter something smaller.")
    exit()

if var2 == "r":
    var2 = random.randint(1,100000)


var1 = var0 * int(var2)
print(var1, var2)
</code></pre>

python variables