2014-02-23 82 views
0

我正在用python 3.3.4编写一个文本游戏,我要求一个名字。有没有一种方法只接受一个名称(输入的一个参数),以及用户是否输入了多个参数。 这是我目前拥有的。Python输入只接受一个参数

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

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

+0

'input()'只接受一个字符串。 –

+0

“,如果用户输入多个参数”...什么? –

+0

@DanielRoseman对不起,对于前。如果有人输入他们的名字为dawson diaz,而我只想他们的名字 – dawsondiaz

回答

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!")