[Tutor] Battleships - Error with blank input

ThreeBlindQuarks threesomequarks at proton.me
Wed May 3 20:46:58 EDT 2023


As Alan mentioned, the code as displayed is not only hard to read but will not pass as valid python with proper indentation.

Where exactly in that code do you want to test for blanks and what do you want to do if they are detected?

Generally, a blank line is matched by "" and if you want to consider anything with nothing but whitespace, that can also easily be matched in various ways depending on what you consider valid input.

So could you just show us a few lines of code where you accept a value and are deciding if the value is valid. Show us what you tried and see why maybe it failed.




Sent with Proton Mail secure email.

------- Original Message -------
On Wednesday, May 3rd, 2023 at 8:13 PM, dn via Tutor <tutor at python.org> wrote:


> On 04/05/2023 10.09, Sharj Ahmed wrote:
> 
> > Hi all,
> > 
> > Need some help with my code.
> > 
> > I've written the below code, but need to add some validation in for when
> > the user inputs nothing.
> > 
> > The blank input for rows and columns causes the application to crash.
> 
> 
> Try:
> 
> "" in "123"
> 
> Does that help?
> 
> There is a feature of Python known as 'truthiness', so
> 
> if row:
> # check if valid row
> else:
> # problem
> 
> > Any help would be greatly appreciated!
> > 
> > Here is my code:
> 
> 
> Sadly, the email formatting was difficult to read, and because newlines
> and indentation were affected, there may be errors we can't detect...
> 
> > The error message that appears is:
> > [image: image.png]
> 
> 
> Attachments do not come through.
> 
> Please copy-paste the text.
> 
> --
> Regards,
> =dn
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list