Skip to content

Instantly share code, notes, and snippets.

@Xotabu4
Last active January 31, 2016 21:58
Show Gist options
  • Save Xotabu4/81b4ea27e91c0f0015aa to your computer and use it in GitHub Desktop.
Save Xotabu4/81b4ea27e91c0f0015aa to your computer and use it in GitHub Desktop.
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')
@Xotabu4
Copy link
Author

Xotabu4 commented Jan 31, 2016

Вот смотри, на 5 строчке делаем userinput.upper() - это чтобы пользователь мог забить и так - exit и так - EXIT - то есть игнорируем заглавные не заглавные буквы. Ну и делаем break чтобы прервать наш бесконечный цикл while True

8 строчка - смотрим не пустая ли наша строка. На самом деле пустые строки когда используются в if то всегда выводятся в False - потому можно написать - if userinput: Но я написал длинную версию тут чтобы показать что проверяется

10 строка - выдернуть из строки кусок из центра - и по краям отступить по 2 символа. До двоеточия - столько отступить сначала, после - сколько с конца.

Ну и на 11 строчке - если мы сюда попали - значит наша не exit и пустая - просто выводим сообщение, и начинается новый цикл while True:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment