In Python, indentation is significant: every contiguous line that is indented to the same level is part of the same block of code.
So when you define a function, the entire block of code needs to be indented to at least the same level:
def foo(bar):
if (bar == "Hello world"):
print(bar)
else:
print("Not bar")
foo("Hello World")
In addition to that, there are scope rules: variables only exist while they are in scope - which means within the block of code that they are defined.
def foo(bar):
if (bar == "Hello world"):
print(bar)
else:
print("Not bar")
foo("Hello World")
print (bar)
So in your code,
replace
is a parameter to the
rep_words
function, and can't be accessed outside it:
def rep_words(replace, sentence):
...
return rep_sentence
rep_input = input().split()
for i in range(0, len(rep_input), 2):
...
replace[first_word] = rep_words
You need to decide what
replace
is, and where it can be accessed, and call your function with the required parameters!