Odpowiedź :
def main():
print("Program obliczajacy informacje o podanym zdaniu")
sentence = input("Podaj zdanie: ")
print(sentence)
punctuation_list = [",", ".", "!", "?", ":"]
sentence_cleaned = sentence
for punctuation in punctuation_list:
sentence_cleaned = sentence_cleaned.replace(punctuation, "")
print(sentence_cleaned)
sentence_list = sentence_cleaned.split()
print(sentence_list)
counter = 0
for word in sentence_list:
print(word)
counter += 1
print("W zdaniu jest ", counter, " wyrazow")
words_with_upper_letters = []
for word in sentence_list:
if word[0].isupper():
words_with_upper_letters.append(word)
if len(words_with_upper_letters) == 0:
print("W zdaniu nie ma wyrazow zaczynajacych sie od wielkiej litery")
else:
for word in words_with_upper_letters:
print(word)
print(sorted(sentence_list))
sentence_tuple = tuple(sentence_list)
print(sentence_tuple)
print(sentence_tuple[0], sentence_tuple[4], sentence_tuple[-1])
sentence_set = set(sentence_list)
print(sentence_set)
print(len(sentence_set))
if len(sentence_list) == len(sentence_set):
print("W zdaniu nie ma duplikatow")
else:
print("W zdaniu jest przynajmniej jeden duplikat")
if len(sentence_list) == len(sentence_tuple) and len(sentence_list) == len(sentence_set):
print("Lista, krotka i set sa rowne")
else:
print("Lista, krotka i set nie sa rowne")
word_to_search = input("Podaj spójnik: ")
if word_to_search in sentence_list:
print("W zdaniu jest spojnik ", word_to_search)
else:
print("W zdaniu nie ma spojnika ", word_to_search)
if __name__ == "__main__":
main()