Python输入只接受一个参数

时间:2014-02-23 19:02:29

标签: python python-3.3

我正在python 3.3.4中编写一个文本游戏,有一次我要求一个名字。有没有办法只接受一个名称,(输入的一个参数),如果用户输入多个arg。 这是我现在拥有的。

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 **')

我猜我需要使用类似的东西,然后if和elif。 非常感谢帮助

1 个答案:

答案 0 :(得分: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!")