我正在编写一个需要垂直打印字符串的代码。我该怎么做呢?班上有人告诉我试试这个:
string = raw_input ('Please enter a string. ')
while string() true:
print string().
我尝试过这个并没有用。有什么想法吗?
答案 0 :(得分: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