检查字符串是否是 Python 中的 Pangrammatic Lipogram
假设我们得到了三个字符串,我们被要求找出哪些字符串是 Pangram、Lipogram 和 Pangrammatic Lipogram。Pangram 是一个字符串或一个句子,其中字母表中的每个字母至少出现一次。Lipogram 是一个字符串或一个句子,其中没有出现字母表中的一个或多个字母。Pangrammatic Lipogram 是一个字符串或句子,其中除了一个字母外,字母表中的所有字母都出现了。
所以,如果输入是这样的 -
pack my box with five dozen liquor jugsto stay in this mortal world or by my own hand go to oblivion, that is my conundrum.
the quick brown fox jumps over a lazy dog
waltz, nymph, for quick jigs ve bud,
那么输出将是 -
The String is a PangramThe String isn't a Pangram but might be a Lipogram
The String is a Pangram
The String is a Pangrammatic Lipogram
示例
让我们看看以下实现以获得更好的理解 -
import stringdef solve(input_string):
input_string.lower()
i = 0
for character in string.ascii_lowercase:
if(input_string.find(character) < 0):
i += 1
if(i == 0):
output = "The String is a Pangram"
elif(i == 1):
output = "The String is a Pangrammatic Lipogram"
else:
output = "The String isn't a Pangram but might be a Lipogram"
return output
print(solve("pack my box with five dozen liquor jugs"))
print(solve("to stay in this mortal world or by my own hand go to oblivion,that is my conundrum."))
print(solve("the quick brown fox jumps over a lazy dog"))
print(solve("waltz, nymph, for quick jigs ve bud"))
输入
pack my box with five dozen liquor jugs输出结果to stay in this mortal world or by my own hand go to oblivion, that is my conundrum.
the quick brown fox jumps over a lazy dog
waltz, nymph, for quick jigs ve bud
The String is a PangramThe String isn't a Pangram but might be a Lipogram
The String is a Pangram
The String is a Pangrammatic Lipogram
以上是 检查字符串是否是 Python 中的 Pangrammatic Lipogram 的全部内容, 来源链接: utcz.com/z/359946.html