Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print('___________________________________________________')
- print('Меню:')
- print(' 1) реверс строки. пример -> ремирп')
- print(' 2) превращение строки в заборчик -> ЗаБоРчИк')
- print(' 3) поиск самого длинного слова слова в строке')
- print(' 0) выйти')
- print('___________________________________________________')
- user_choice = input('Введите число для выбора работы программы (например 1, 2 или 3): ')
- def askString():
- return input('Введите слово или несколько слов: ')
- def stringReverse(string):
- # всезнайки с форума напишут так:
- # print( string[::-1] )
- # а я учусь и напишу так
- string_length = len(string)
- result = ''
- while (True):
- result = result + string[string_length - 1]
- string_length = string_length - 1
- if string_length == 0:
- break
- return result
- def stringZabor(string):
- string_length = len(string)
- currentCharIndex = 0
- boolFlagZabora = True
- result = ''
- while (True):
- if boolFlagZabora == True:
- result = result + string[currentCharIndex].upper()
- boolFlagZabora = False
- else:
- result = result + string[currentCharIndex].lower()
- boolFlagZabora = True
- currentCharIndex = currentCharIndex + 1
- if currentCharIndex == string_length:
- break
- return result
- def stringLongWordSearch(string):
- wordList = string.split()
- longest_word = max(wordList, key=len)
- return longest_word
- #match/case не работает в питон 3.9 поэтому делаю на любимых if'ах
- if user_choice[0:3] == "2+1" or user_choice[0:3] == "2 1" or user_choice[0:3] == "2и1" or user_choice[0:2] == "21":
- print(stringReverse(stringZabor(askString())))
- elif user_choice[0:3] == "1+2" or user_choice[0:3] == "1 2" or user_choice[0:3] == "1и2" or user_choice[0:2] == "12":
- print(stringZabor(stringReverse(askString())))
- elif user_choice[0] == "1":
- print(stringReverse(askString()))
- elif user_choice[0] == "2":
- print(stringZabor(askString()))
- elif user_choice[0] == "3":
- print(stringLongWordSearch(askString()))
- elif user_choice[0] == "0":
- print("Пользователь нажал выход")
- else:
- print('Ошибка, неверный выбор пользователя.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement