# python program
import string
def main():
while 1:
try:
n = int(input('How many sentences you want to store:'))
if n >= 0:
break
else:
n = 5
break
except ValueError:
print('Please enter a valid number.')
sentences = []
print('Enter the sentences:')
for i in range(n):
sentences.append(str(input()).lower())
for i in range(n):
print("Enter 1 to see a sentence")
print("Enter 2 to see the whole list")
print("Enter 3 to change a sentence")
print("Enter 4 to switch words")
print("Enter 5 to count letters")
try:
option = int(input())
if option == 1:
print(sentences[i])
elif option == 2:
print('\n').join(sentences)
elif option == 3:
new = input('Enter a new sentence:\n')
sentences[i] = new
elif option == 4:
sentences[i] = sentences[i][::-1]
print(sentences[i])
elif option == 5:
_count = sum(list(map(lambda x: len([char for char in x if char not in string.punctuation+'']), sentences)))
print('There are {} letters.'.format(_count))
except ValueError:
print('Enter one of the option')
if __name__ == '__main__':Answer provided by www.AssignmentExpert.com
Comments