我正在尝试计算单词中的字母数,然后多次打印用户输入的单词

时间:2016-01-12 11:18:18

标签: python python-3.x

print ("Enter a word")
word = str(input())
total = len(word)
count = 0
while (total > count):
    count+1
    print(word)

所有内容都适用于while循环,当我输入内容时,它会永远重复这个词。

3 个答案:

答案 0 :(得分:4)

尝试:

count = count + 1

count += 1

不要用count + 1更新计数;

答案 1 :(得分:2)

更pythonic的方法是使用for循环:

print ("Enter a word")
word = str(input())
total = len(word)

for i in range(total-1):
    print(word)

答案 2 :(得分:0)

另一种解决方案是使用字符串的乘法:

print((word+'\n')*len(word))