+ 1
Why wonât my if statement work
https://code.sololearn.com/c666mkc3yhSd/?ref=app The if statement wonât work (the code is meant to simulate bunny populations and the if statement is to kill bunnyâs that are over 9 generations old)
13 Antworten
+ 3
you need to indent every line which should be included in the if statement - proper indention is essential in python! it is basically replacing the curly braces like in java or c
+ 3
First, check your indentions, indention in defining functions and if statements are required.
Second, what is your desired output? Can you give some sample inputs and outputs? I can't quite what you're trying to program. Thanks, that will help.
+ 2
ă Nicko12 ă thank you but that is not the error at hand the error is with the indentation what you pointed out would cause a second though so thank you but i could have FiguredïżŒ that oot on my own
+ 1
4 spaces or 1 tab
+ 1
Ok I'll figure out. Wait a sec.
+ 1
its ok i got it working i dont need you to solve my problem with new code i need you to show me why my codes wrong
+ 1
Ben Carvalho Well.. the reason why I'm asking for the purpose of the program is for the syntaxes and to know what you want to do. Anyway I'll just point out what causes errors.
x-=population.[0]
remove(population.[0])
Should be
population.remove(population[0])
remove is a method of list so it must be followed by the list and a dot.
+ 1
Oh ok, anyway.
"def" requires indention too
# like this
def function():
return something
+ 1
ă Nicko12 ă thank you
0
Martin Ed how do i know if its indented
0
ă Nicko12 ă it says in the post the if statment is to kill bunnys 9 genarations old so if list > 9 remove first item in list
0
ă Nicko12 ă no that is so far from what its meant to do did you even look at my code?
0
Martin Ed where do i put the 4 spaces