+ 2
Please, how do i consider a situation where the user inputs a character or alphabet instead of an integer...
something like .. elif guess == ?
4 Respuestas
+ 5
When you take input in Python, it's always in string format (if you don't transform it), so with your ifs and elses you just ask for string. For example:
if guess == 'a': ...
You can also define a number of letters that are accepted, by using any container, for example:
if guess in ('a', 'b', 'c'):
or:
if guess in ['e', 'E']:
(I'm not sure what exactly you want to do, but I hope this helps anyway.)
+ 5
In addition to above two ways, you can also check of the input is in your desired format or not and can take steps accordingly.
You can do it using an if-else block:
if isinstance(your_input, type(e.g. int, float, string or any of your defined type))
+ 3
thanks everyone🤗🤗
+ 1
🙌def ask_name():
while True: name = raw_input("What is your name?")
if name.isalpha():
return name
else:
print("Please use only letters, try again")