[Solved] Trouble with call function [closed]


Python is dependant on indentation. In order for the program to work you need to add the correct indentation to your code. That involves 4 spaces for each loop or flow control.

Here are a few that do:

def 
if
while 
for

Your problem is that Python does not know where to end the while loop without indentation.

Here is an example:

for in range(5):
print('Working')
if i == 4: 
print('yes')
else: 
print('no')

There are two ways to indent this.

How does Python know whether the if statement should be in the for loop or not? Both the following are valid with very different results:

for in range(5):
    print('Working')
if i == 4: 
    print('yes')
else: 
    print('no')

OR

for in range(5):
    print('Working')
    if i == 4: 
        print('yes')
    else: 
        print('no')

In the first the while prints out the message 5 times and then the if statement starts.

In the second the if is part of the while loop so it runs 5 times as well as printing the message.

4

solved Trouble with call function [closed]