0

I am writing a text game in python 3.3.4, at one point I ask for a name. Is there a a way to only accept one name, (one argument to the input) and if the user inputs more than one arg. Here is what I currently have.

name =input('Piggy: What is your name?\n').title()
time.sleep(1)
print('Hello, {}. Piggy is what they call me.'.format(name))
time.sleep(1)
print('{}: Nice to meet you'.format(name))
time.sleep(1)
print('** Objective Two Completed **')

I am guessing I will need to use something like while, and then if and elif. Help is greatly appreciated

9
  • input() only accepts one string. Commented Feb 23, 2014 at 19:03
  • "and if the user inputs more than one arg" ... what? Commented Feb 23, 2014 at 19:04
  • @DanielRoseman Sorry, for ex. if someone inputs their name as dawson diaz, whereas I only would like their first name Commented Feb 23, 2014 at 19:05
  • @IgnacioVazquez-Abrams I would like only a first name. Commented Feb 23, 2014 at 19:05
  • Instead of “What is your name?” you could ask “How should I call you?” Commented Feb 23, 2014 at 19:18

1 Answer 1

3
while True:
    name = input("What is your name? ").strip()
    if len(name.split()) == 1:
        name = name.title()
        break
    else:
        print("Too long! Make it shorter!")

enter code here
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.