Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do I ask the user to input the string only. If there isn't such a thing how do I set it so that if they enter anything else it would ask the user to re-enter.

This is what I have tried (it doesn't work):

name = raw_input("Enter name: ")
 if name != str(name):
     name = raw_input("Error, please re-enter : ")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
146 views
Welcome To Ask or Share your Answers For Others

1 Answer

while True:
    userInput = raw_input("Enter a string only")
    if type(userInput) not str:
        continue
    else:
        print "You entered a STR data type. Congratulations"
        break

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...