#trying to code battleship
16 messages · Page 1 of 1 (latest)
In your
if __name__ == "__main__":
main()
play_game()
play_game() will run regardless of whatever main() does
By convention you should have most logic inside main() in the sense, probably running play_game() from of main() will be the best approach
so all the headers like play_game , Get_target , display_grid i should move under main ?
No, main() in your case does the following things
- Gives instructions
- Starts a new game
- Displays hall of fame
- Quits
For statement 2 you are just breaking out of the function and letting the following function run which isn't conventional correct and leads to errors.
You should instead have play_game() inside of elif num == 2 and have main() as your sole function inside if __name__ statement
oooh i understand ! thank you so much !! i will try to accomplish this 🙂
Good luck!
hell ya that fix it !!! thx so much i spent so much time on that haha you da best !!!
You're welcome 
hi again if you have time to help again i love it if you cant all good 🙂 . im stuck in a infi loop . when i start the code i press "2" play then when i want to exit the game i press "q" this will sent be back to the main menu where then i press "4" to quit and it promps me back in the game were now when ever i do "4" or "q" is will keep bringing be back to each other🥲
https://paste.pythondiscord.com/abatodihas this is the new code
Am busy rn but a simple solution would be to switch your break with a return in your press 2
no worries !! only if you have time 🙂 and that kina worked it ends the game completely but its supost to go back to the main menu
im gana take a break from this for now. i been doing it to long haha thx you for your help tho 🙂
@azure swift did you fix it?
thx for checking up with me 🙂 unfortunately i was unable to. its in the "am" where i am so i got to go sleep now, but thanks again for your help tonight !!