![](/img/trans.png)
[英]How can I grab the user inputs and print the letter count of each word he/she typed?
[英]I'm trying to count the number of letters in a word and then print the word typed by the user that many times
print ("Enter a word")
word = str(input())
total = len(word)
count = 0
while (total > count):
count+1
print(word)
一切工作到while循环,当我输入某些内容时,它会永远重复一个单词。
尝试:
count = count + 1
要么
count += 1
不要使用count + 1更新count;
一种更pythonic的方法是使用for循环:
print ("Enter a word")
word = str(input())
total = len(word)
for i in range(total-1):
print(word)
另一个解决方案是使用字符串的乘法:
print((word+'\n')*len(word))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.