Is there a way I can prevent users from entering numbers with input()
<p>I would like to prevent the user from entering numbers to save troubles down the line in my program. I know how to use try, except with int(input()) to prevent strings being entered when integers are required but I was wondering if a similar thing was possible with str(input()).</p>

<p>For example, if the user was asked for their name and they entered, "1994", they would receive and error message for entering an integer.</p>

<p>Use a <code>try-except</code> with an <code>else</code> block in which you'll raise a <code>ValueError</code> if an Exception <em>didn't</em> occur during conversion to an <code>int</code> (which means the input <em>is</em> an <code>int</code>:</p>

<pre><code>v = input("&gt; ")
try:
    _ = int(v)
except:
    pass
else:
    raise ValueError("input supplied should be of type 'str'")
</code></pre>

<p>This will catch any <em>numbers</em> entered by raising the exception in the <code>else</code> block:</p>

<pre><code>&gt; 1992

ValueErrorTraceback (most recent call last)
&lt;ipython-input-35-180b61d98820&gt; in &lt;module&gt;()
      5    pass
      6 else:
----&gt; 7    raise ValueError("input supplied should be of type 'str'")

ValueError: input supplied should be of type 'str'
</code></pre>

<p>And allow strings by <code>pass</code>ing in the <code>except</code>:</p>

<pre><code>&gt; jim

v
Out[37]: 'jim'
</code></pre>

<p>Alternatively, you could also do this with <code>any</code> and <code>isdigit</code>:</p>

<pre><code>v = input("&gt; ")
if any(s.isdigit() for s in v):
    raise ValueError("input supplied should be of type 'str'")
</code></pre>

<p>This checks to see if <code>any</code> characters are digits and if so raises the error. </p>

<hr>

<p>You could prevent floats too, but this starts to get ugly:</p>

<pre><code>v = input("&gt; ")
for f in [int, float]:
    try:
        _ = f(v)
    except:
        pass
    else:
        raise ValueError("Numbers not allowed")
</code></pre>

python string python-3.x input