Why is Autolab saying my program is returning empty strings? (Tic-Tac-Toe game in Python 3) - tic-tac-toe

My class is doing a tic-tac-toe game in Python 3.10, and I was wondering why the code sometimes returns as empty. The tic-tac-toe board should look like this when it's printed:
enter image description here
For instance, if I have the code
def isFull(self):
for column in range(self.width):
for row in range(self.height):
if self.data[row][col]=='':
return False
Autolab returns with: Your data: '[[' ', ' '], [' ', ' ']]',
Correct data: '[[' ', ' '],['X', ' ']]'
A lot of the rejected code in Autolab looks like it has the same problem, so I was wondering what I could do to fix it. I have tried making a separate class for the functions, though it wouldn't be sustainable for the entire 170+ lines of code. Thank you in advance.

Related

What should be the structure if I want to use concat and encodeURI in the same JSON for Azure DevOps pipeline

I have a code in my logic app that gets a list of warehouses from an API URL. In it, I am trying to define a parameter that picks my URL for the azure DevOps pipeline when deploying my logic app, but when I run the pipeline I get the error
Deployment template validation failed: 'The template resource
'MyLogicApp' at line '1' and column '1465' is not valid: Unable to
parse language expression
'concat('/v2/datasets/#{encodeURIComponent(encodeURIComponent(''https://',parameters('myApiUrl'),'.com''))}/tables/#{encodeURIComponent(encodeURIComponent('msdyn_warehouses'))}/items')':
expected token 'RightParenthesis' and actual 'Identifier'.. Please see
https://aka.ms/arm-template-expressions for usage details.'.
This is what my json looks like
"
[
concat
(
'
/v2/datasets/#
{
encodeURIComponent
(
encodeURIComponent
(
'
'
https://
',
parameters
(
'
myApiUrl
'
),
'
.com
'
'
)
)
}/tables/#
{
encodeURIComponent
(
encodeURIComponent
(
'
msdyn_warehouses
'
)
)
}/items
'
)
]
"
If I use it without concat, it works
"path": "/v2/datasets/#{encodeURIComponent(encodeURIComponent('https://bla.bla3.com'))}/tables/#{encodeURIComponent(encodeURIComponent('msdyn_warehouses'))}/items"
Is there a specific way to format concat and encodeURI together that I am missing?
After checking thoroughly, you are receiving the above-mentioned error as because of the incomplete template (i.e., it misses a right parenthesis).
the uri from the parameter within the encoding statement
In that case you need to include concat() inside the encodeURIComponent and below is how you need to frame.
/v2/datasets/#{encodeUriComponent(encodeUriComponent(concat('https://',parameters('myApiUrl'),'.com')))}/tables/#{encodeURIComponent(encodeURIComponent('msdyn_warehouses'))}/items

How to parse keywords and strings from a line of text

Have a file keywords.tx with
Commands:
keywords = 'this' & 'way'
;
StartWords:
keywords = 'bag'
;
Then a file mygram.tx with
import keywords
MyModel:
keyword*=StartWords[' ']
name+=Word[' ']
;
Word:
text=STRING
;
'''
My data file has one line with "bag hello soda this way".
Would like to see result have attributes of keyword='bag' name='hello soda' and command='this way'.
Not sure how to get grammar to handle: keywords words keywords making sure that 2nd keywords are not included in the words. Another way to express is startwords words commands
If I understood your goal you can do something like this:
from textx import metamodel_from_str
mm = metamodel_from_str('''
File:
lines+=Line;
Line:
start=StartWord
words+=Word
command=Command;
StartWord:
'bag' | 'something';
Command:
'this way' | 'that way';
Word:
!Command ID;
''')
input = '''
bag hello soda this way
bag hello soda that way
something hello this foo this way
'''
model = mm.model_from_str(input)
assert len(model.lines) == 3
l = model.lines[1]
assert l.start == 'bag'
assert l.words == ['hello', 'soda']
assert l.command == 'that way'
There are several things to note:
You don't have to specify [' '] as a separator rule in your repetitions as by default whitespaces are skipped,
To specify alternatives use |,
You can use a syntactic predicate ! to check if something is ahead and proceed only if it isn't. In the rule Word this is used to assure that commands are not consumed by the Word repetition in the Line rule.
You can add more start words and commands simply by adding more alternatives to these rules,
If you want to be more permissive and capture commands even if user specified multiple whitespaces between command words (e.g. this way) you can either use regex matches or e.g. specify match like:
Command:
'this ' 'way' | 'that ' 'way';
which will match a single space as a part of this and than arbitrary number of whitespaces before way which will be thrown away.
There is a comprehensive documentation with examples on the textX site so I suggest to take a look and go through some of the provided examples.

Save the xml result to a column in a SQL table

I have copied the code somewhere in the internet and have created an html table using something like
''FOR XML RAW (''TR''), ELEMENTS, TYPE) AS ''TBODY''',
' FOR XML PATH (''''), ROOT (''TABLE'')'`
in SQL. The result is as expected which is an HTML table, below is the snippet.
Can someone point me on how to get the HTML string and save it into a column in my table. My thought was to get the result and save it as a string then insert it into a column in my table but after sometimes I failed.
The code example can be retrieve from https://www.mssqltips.com/sqlservertip/5025/stored-procedure-to-generate-html-tables-for-sql-server-query-output/
Cheers!! it's simple but I went around the globe. What I did was adding SET #Myvariable = in the dynamic query. Previously, I have tried so hard to assign the result into a variable outside the dynamic query which will never work for me.
Originally:
SET #DynTSQL = CONCAT (
'SELECT (SELECT '
, #columnslist
,' '
, #restOfQuery
,' FOR XML RAW (''TR''), ELEMENTS, TYPE) AS ''TBODY'''
,' FOR XML PATH (''''), ROOT (''TABLE'')'
)
What I did:
SET #DynTSQL = 'SET #SQLQuery1 =('+CONCAT (
'SELECT (SELECT '
, #columnslist
,' '
, #restOfQuery
,' FOR XML RAW (''TR''), ELEMENTS, TYPE) AS ''TBODY'''
,' FOR XML PATH (''''), ROOT (''TABLE'')'
)+')'
The result will be assigned into the #SQLQuery1.
Cheers!!!

Using the trim function to narrow down results set

I need to gather data from two columns, concat them so that it's only the first six of the first column and the last six of the second column, separated by ' + '. Some have been input with weird spaces in front or in back, so we must also use the trim feature and get rid of all NULL. I haven't had any issues with the first part, but am struggling to use the trim feature in a way that gives the desired output.
Output needs to look like this:
Input Data sample:
The following code returns results, but the output doesn't match so I know the trim is wrong:
SELECT CONCAT(SUBSTRING(baseball, 1, 6), ' + ',
SUBSTRING(football, -6)) AS MYSTRING
FROM datenumtest2
WHERE baseball IS NOT NULL AND football IS NOT NULL;
I also tried the following, but get an error message about the parameters being incorrect:
SELECT CONCAT(SUBSTRING(LTRIM(baseball, 1, 6)), ' + ',
SUBSTRING(RTRIM(football, -6))) AS MYSTRING
FROM datenumtest2
WHERE baseball IS NOT NULL AND
football IS NOT NULL;
I'm still new to this site and learning, but I have tried to include as much as I can! If there is other information that I can add to help, please let me know.
You just need to use Trim() on the column(s), before using Substring() function on them:
SELECT CONCAT(SUBSTRING(TRIM(baseball), 1, 6), ' + ',
SUBSTRING(TRIM(football), -6)) AS MYSTRING
FROM datenumtest2
WHERE baseball IS NOT NULL AND
football IS NOT NULL;

Strip special characters and space of a DB column to compare in rails

I have 4 types of last_name:
"Camp Bell"
"CAMPBELL"
"CampBellJr."
"camp bell jr."
Now, in rails when an user is searched by it's last name like camp bell, I want to show all the 4 records. So, I tried:
RAILS
stripped_name = params[last_name].gsub(/\W/, '')
#=> "campbell"
User.where("LOWER(REPLACE(last_name, '/\W/', '')) LIKE ?", "#{stripped_name}%")
Give me only 2 records with following last_name:
"CAMPBELL"
"CampBellJr."
I guess, this is because, the mysql REPLACE is not working correctly with regex.
Any ideas?
EDIT
Guys, sorry for the confusion. My idea is to strip off all special characters including space. So I'm trying to use \W regex.
For example, the input can be: camp~bell... But, it should still fetch result.
You can check for both stripped_name without space and ones that include both names seperated with space like this.
stripped_name = params[last_name].gsub(/\W/, '')
split_names = params[last_name].split(" ")
User.where('name LIKE ? OR (name LIKE ? AND name LIKE ?)', "%#{stripped_name}%", "%#{split_names[0]}%", "%#{split_names[1]}%")
Next step would to search for complete array of split names not just first two.
Here my solution:
User.where("REPLACE(last_name, ' ', '') ILIKE CONCAT ('%', REPLACE('?', ' ', ''),'%')", stripped_name)
ILIKE is like LIKE but the I is for insensitive case.
To understand easily step by step:
lastname ILIKE '%campbell% you need % because you want lastname
contain this string, not necessary at the begin or the end of you
string.
'campbell%' => search string who begin by campbell
'%campbell' => search string who finish by campbell
We need generate '%campbell%, so we use CONCAT for that
I just use a simply REPLACE, but maybe you should use a regex.