+ 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)

7th Jan 2021, 10:24 AM
Ben Carvalho
Ben Carvalho - avatar
13 odpowiedzi
+ 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
7th Jan 2021, 10:29 AM
Martin Ed
Martin Ed - avatar
+ 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.
7th Jan 2021, 10:29 AM
noteve
noteve - avatar
+ 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
7th Jan 2021, 10:49 AM
Ben Carvalho
Ben Carvalho - avatar
+ 1
4 spaces or 1 tab
7th Jan 2021, 10:34 AM
Shadoff
Shadoff - avatar
+ 1
Ok I'll figure out. Wait a sec.
7th Jan 2021, 10:37 AM
noteve
noteve - avatar
+ 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
7th Jan 2021, 10:38 AM
Ben Carvalho
Ben Carvalho - avatar
+ 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.
7th Jan 2021, 10:46 AM
noteve
noteve - avatar
+ 1
Oh ok, anyway. "def" requires indention too # like this def function(): return something
7th Jan 2021, 10:50 AM
noteve
noteve - avatar
+ 1
《 Nicko12 》 thank you
7th Jan 2021, 10:51 AM
Ben Carvalho
Ben Carvalho - avatar
0
Martin Ed how do i know if its indented
7th Jan 2021, 10:31 AM
Ben Carvalho
Ben Carvalho - avatar
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
7th Jan 2021, 10:34 AM
Ben Carvalho
Ben Carvalho - avatar
0
《 Nicko12 》 no that is so far from what its meant to do did you even look at my code?
7th Jan 2021, 10:36 AM
Ben Carvalho
Ben Carvalho - avatar
0
Martin Ed where do i put the 4 spaces
7th Jan 2021, 10:44 AM
Ben Carvalho
Ben Carvalho - avatar