Last active
January 31, 2016 21:58
-
-
Save Xotabu4/81b4ea27e91c0f0015aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print('#### Welcome to word cuter 1.0! #####') | |
while True: | |
userinput = input('Please, type any word. It will be reduced by 2 characters from begin and from end: ') | |
if userinput.upper() == 'EXIT': | |
print('You entered /exit/ . Closing application') | |
break | |
elif userinput != '': | |
print('Result is:') | |
print(userinput[2:-2]) | |
else: | |
print('Got empty string. Enter word, or enter: exit to close application') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Вот смотри, на 5 строчке делаем
userinput.upper()
- это чтобы пользователь мог забить и так - exit и так - EXIT - то есть игнорируем заглавные не заглавные буквы. Ну и делаем break чтобы прервать наш бесконечный цикл while True8 строчка - смотрим не пустая ли наша строка. На самом деле пустые строки когда используются в if то всегда выводятся в False - потому можно написать -
if userinput:
Но я написал длинную версию тут чтобы показать что проверяется10 строка - выдернуть из строки кусок из центра - и по краям отступить по 2 символа. До двоеточия - столько отступить сначала, после - сколько с конца.
Ну и на 11 строчке - если мы сюда попали - значит наша не exit и пустая - просто выводим сообщение, и начинается новый цикл
while True: