2013-09-27 235 views
-1
# This program says hello and asks for my name, then repeats it. 
print('Hello world!') 
print('What is your name?') 
myName = input() 

while 
    print('It is nice to meet you, ' + myName) 

我的问题是什么我放在哪里,而为“而”? 我正试图学习如何使用while循环,但我不知道该如何放置,才能让它永远重复您的名字。 在此先感谢!如何使用在这种情况下

回答

0

如果你想输入一个名称和inifinetly打印使用:

print('Hello world!') 
print('What is your name?') 
myName = input() 

while True: 
    print('It is nice to meet you, ' + myName) 

如果你想输入一个名称,打印出来,然后输入另一个等等,用途:

print('Hello world!') 
while True: 
    print('It is nice to meet you, ' + input('What is your name? ')) 
0

您可以使用任何总是评估为True的条件。最明显的(因此是优选的)方式是

while True: 
    print('It is nice to meet you, ' + myName) 

还要注意的是,你并不需要使用字符串连接与print()

print('It is nice to meet you,', myName)