Accept an input as a word and not an integer
26,842
Solution 1
Just remove the int
call! That is what makes the statement accept integer numbers only.
I.e, use:
test = input('This takes any string as an answer')
Solution 2
Remove the type cast to int
test = input('This only takes a word as an answer :')
A demo
>>> test = input('This only takes a word as an answer :')
This only takes a word as an answer :word
>>> test
'word'
Note - From the docs
The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that
Therefore input
automatically converts it to a str
and there is no need of any explicit cast.
Author by
Deduplicator
Updated on April 15, 2020Comments
-
Deduplicator about 4 years
How to make word inputs in Python I want to be able to have the computer to ask a question to the user like
test = int(input('This only takes a number as an answer'))
I want to be able to have 'test' not be a number, rather a word, or letter.
-
mins about 9 yearsCan that helps? Python - How to check if input is a number.
-