Can I use "1" instead of "0"?


Hello, I'm sorry this is not linked with any exercise in particular; It's for the battlship in general:

Maybe it's an error from "my" code, but when figuring out where the ship is, I have to type "0, 0" to find it in all up left of the board; If it's normal, isn't possible to make the user / player able to type 1 instead ? It would seems more natural, when making someone try the game, I'm pretty sure using 0 for the firt bloc will seems more legit..
And if it's a misstake from me, what / where can it be ? ( Sorry for eyes pain of my language)

  • Maybe can I add a " -1 " on the ligne that control the player input ?

  • Well, yes, it works, so... Sorry =/ Talked befor thinking.. -_-
    So I'm now looking for how to delete a topic instead ...


its much easier to manipulate user input, so if you want to do this, manipulate user input.


Thanks stetim94 ! =)
You were much quicker than my edits ^^
That's what I did yeah ! Worked =) If only I was thinking sometimes befor crying help.. -_-


But, Maybe can I use that topic for another question ?
Is it possible to make another elif in case of no input are entered ?
I tried " if guess_row == "" " So with nothing ino input, but ofc that's not working..


the problem is that if the user enters nothing, its basically an empty string, which then needs to be converted to an integer. This doesn't work (valueerror is raised because value is not valid), so what you need to do is something like this:

while True:
        guess_row= int(raw_input( 'Guess Row: '))
        guess_col= int(raw_input( 'Guess Col: '))
    except ValueError:
        print "that is not valid, try again"

try/except is not taught in this course, it allows you to handle errors (like invalid input)


Yeah I was pretty sure I would have to add a total loop at another place, since just adding an elif inside the code doesnt worked; (like you said, no input is not an input, ofc, so it return an error.) .And so, where must I insert that loop in ? Arround the "user input" segment I presume ?
And a big thanks for you to have came back =3


Well, given this is outside the scope of the exercise, there is no place you have to add it. You are free to choice.

personally, i would first validate the user input is valid. Why run the rest of your program, while the user input is not valid?


Was just to say something like "You did not entered anything"
Was just a way to make the code prepared to anything XD
Kind of a nose-picking indeed, but yeah that's not really something ^^
And I understand the principe, maybe i'll figure it later, i'll be able to come back !

Thanks for hints ! And more, for your time =) Really pleasant !


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.