2014-02-18 104 views
0

我正在編寫需要垂直打印字符串的代碼。我該怎麼做呢?我班上有人告訴我試試這個:python 2.7.6在使用循環時垂直打印字符串

string = raw_input ('Please enter a string. ') 
    while string() true: 
     print string(). 

我試過這個,但沒有奏效。有任何想法嗎?

回答

2

如果你要打印一個新行的字符串的每個字符,你可以遍歷字符串:

user_input = raw_input ('Please enter a string. ') # store the string if a variable 
for c in user_input:  # for each character 'c' in the input 
    print(c)    # print it. The print function add a new line character at each call