0

What is the reason count is not being updated

https://sololearn.com/compiler-playground/cI7P06yUE1SJ/?ref=app I have been writing a huge file this is a part of it i checked everything works just fine but the count is not being increased I am not sure How to fix this

2nd Dec 2024, 12:52 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
11 odpowiedzi
+ 5
Without complete code, it's hard to say where things are failing. But I would check the IF statement first. Add a print statement to confirm this is getting called. if valid_boom_loc(actual_board,bom_loc)==helper.HIT_SHIP: count2=count2+1 print("Count updated:", count2)
2nd Dec 2024, 1:05 AM
Jerry Hobby
Jerry Hobby - avatar
+ 3
from the available info you updated, are you sure your if condition is returning True?
2nd Dec 2024, 3:52 AM
Bob_Li
Bob_Li - avatar
+ 3
Without seeing the complete code, or at least the relevant parts, its hard to say for certain where the bug is. Is your count2 a global variable? perhaps it's being overwritten somewhere else. Or if it is a return value, maybe it's not being assigned properly.
2nd Dec 2024, 6:05 AM
Bob_Li
Bob_Li - avatar
+ 2
Bob_Li yeah i just sort of knew where the error is since i already tested the rest of the code so i just wanted to get a hint regarding if i am using return incorectly in python or if i should test something else , getting a comment thats not related to the return i could actually focus on the the only other possible problmatic part , i did not provide the whole code since it would be too lengthy to read , i thought of providing it if i fail to debug after asking abruptly like this ,thank you
2nd Dec 2024, 6:10 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 1
Jerry Hobby it was more tricky than i thought i was updating the value of the location i have and as soon as it is updated the if condition begins to return False all the time since (i made the function this way to avoid accessing infi loops it slipped over my mind that its related directly to the loc at each moment) rearranged the location and it is working as it should
2nd Dec 2024, 1:18 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 1
Yeah i did run the code whats around 8 times in a row checking for diffrent inputs
2nd Dec 2024, 5:09 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 1
It seems all the code are in lowercase, except "helper.HIT_SHIP". Better use an IDE debugger and see what the values are. I won't be surprised if it holds None.
2nd Dec 2024, 7:56 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
Python not having constants is a drawback. I wonder why they did not use enums? It's the nearest thing to const in Python. https://arjancodes.com/blog/python-enum-classes-for-managing-constants/
2nd Dec 2024, 3:50 PM
Bob_Li
Bob_Li - avatar
+ 1
Bob_Li I guess the python maintainers want to keep the language as easy to access as possible. With capital letters variable as constant is more readable for people with little coding experience.
2nd Dec 2024, 3:55 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
Learning something new everyday i will go read about it thank you
2nd Dec 2024, 3:56 PM
Dareen Moughrabi
Dareen Moughrabi - avatar
0
Wong Hei Ming for the captial letter it was an intentinal choice in order. To remember not to change this element value as for its value it is a number used to map to a certain color
2nd Dec 2024, 3:43 PM
Dareen Moughrabi
Dareen Moughrabi - avatar