这就是我目前的处境。。。把这些放在一起的最佳方式是什么,这样程序就会不断提示用户输入,直到满足10个字符的要求?
def char_frequency(str1):
char_dict = {}
for n in str1:
keys = char_dict.keys()
if n in keys:
char_dict[n] += 1
else:
char_dict[n] = 1
return char_dict
print(char_frequency('elevator'))
def string_length(str1):
count = 0
for char in str1:
count += 1
return count
print(string_length('adkjfaslnfafs'))
您可以使用while
循环:
while True:
a = input("Please enter a text: ")
if len(a.strip()) >= 10:
print(a[2:]) # Do whatever you want with the input
break