Найти - Пользователи
Полная версия: Проблема в задаче с input
Начало » Центр помощи » Проблема в задаче с input
1
juca
Есть задача путём переставления части строки и добавления другой строки из слова hello получить lloheay. Решение такое:

 word = input ("Input word: ")
if word == "hello":
   s1 = word[:2]
   s2 = word[2:]
    word = s1 + s2 + "ay"
    print word
else:
    print "wrong word"

Результат такой:

Input word: hello
Traceback (most recent call last):
File “python”, line 1, in <module>
File “<string>”, line 1, in <module>
NameError: name ‘hello’ is not defined

В чём ошибка?
wallet
juca
word = input (“Input word: ”) if word == “hello”: s1 = word s2 = word word = s1 + s2 + “ay” print word else: print “wrong word”

 word = raw_input("Input word: ")
scidam
juca
В чём ошибка?

Желательно, постепенно переходить на Python3.x, там input будет работать “правильней”.
juca
scidam
Спасибо за совет, но это я пока учусь в codecademy. В уроках input работал правильно, а в этой задаче что-то пошло не так.
juca
wallet
Благодарю, помогло.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB