+ 2

Please, how do i consider a situation where the user inputs a character or alphabet instead of an integer...

something like .. elif guess == ?

7th Sep 2018, 9:24 PM
wizHÆVÊN§
wizHÆVÊN§ - avatar
4 odpowiedzi
+ 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.)
7th Sep 2018, 9:48 PM
HonFu
HonFu - avatar
+ 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))
8th Sep 2018, 2:55 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 3
thanks everyone🤗🤗
8th Sep 2018, 6:18 AM
wizHÆVÊN§
wizHÆVÊN§ - avatar
+ 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")
9th Sep 2018, 5:25 PM
Sri Raman Prasad