+ 1

Here the name takes any data type. How can I make sure it only accepts a string?

https://code.sololearn.com/cEus6ZnBuRlp/?ref=app

11th Nov 2017, 7:32 AM
Jyoti Kaurav
Jyoti Kaurav - avatar
5 Respuestas
+ 8
I don't think u can prevent input() from taking a number. What u can do is to make ur code raise an exception when someone enters a number, say: string = input("Do not enter a number:") try: string = int(string) except ValueError: print("Good, you didn't enter a number") else: print("Why did u enter a number?") OR string = input("Do not enter a number:") if string.isalpha(): print("Good, you didn't enter a number") else: print("Why did u enter a number?")
11th Nov 2017, 8:14 AM
David Akhihiero
David Akhihiero - avatar
11th Nov 2017, 8:11 AM
Oma Falk
Oma Falk - avatar
+ 7
str(input()) instead of input()
11th Nov 2017, 7:38 AM
qwerty
qwerty - avatar
+ 4
str.isalpha()
11th Nov 2017, 8:06 AM
Oma Falk
Oma Falk - avatar
+ 2
ok. well its converting all the digits to string. hence not much difference
11th Nov 2017, 7:40 AM
Jyoti Kaurav
Jyoti Kaurav - avatar