Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
SamAnw

My program states "not all arguments converted during string formatting"

Don't forget to use the forum's code tag:

a =1
while a==1:
    Numcas = int(input("How many cases do you have?: "))
    countcas = 1
    state = a = input('Enter the amount of columns and rows in your game: ')
    h = a.split(",")
    coltotal = int(h[0])    
    rowtotal = int(h[1])
    if (2<=coltotal<=1000 and 2<=rowtotal<=1000):
        while (countcas <= Numcas):
            question2 = 'Enter the starting position in the case #{}: '
            positionst = input(question2.format(countcas))
            position = positionst.split(",")
            colstart = int(position[0])
            rowstart = int(position[1])
            question4 = 'Enter the finishing position number in the case #{} '
            positionend= input(question4.format(countcas))
            positionen = positionend.split(",")
            colend = int(positionen[0])
            rowend = int(positionen[1])
            countcas+=1
            seqcount = 1
            if positionst[0] % 2 == 0 and positionst[1] % 2 == 0 and positionend[0] % 2 ==0 and positionend[1] % 2 ==0:
                print ("TRUE")
            if positionst[0] % 2 !=0 and positionst[1] % 2 !=0 and positionend[0] % 2 !=0 and positionend[1] % 2 !=0:
                print ("TRUE")
            if positionst[0] % 2 !=0 and positionst[1] % 2 ==0 and positionend[0] % 2 !=0 and positionend[1] % 2 ==0:
                print ("TRUE")
            if positionst[0] % 2 ==0 and positionst[1] % 2 !=0 and positionend[0] % 2 ==0 and positionend[1] % 2 !=0:
                print ("TRUE")
    else:
        print ("FALSE")

 

The issue is that positionst and positionend are strings. This causes the % operator to be interpreted as string interpolation. You probably want to replace positionst[0] with colstart, positionst[1] with rowstart, etc... Those are your integers which will have % do the modulus operation like I think you are expecting.

 

Feel free to ask more questions.

Recommended Posts

Posted · Original PosterOP

Hello, I've been working on a python code to trace the movement of the bishop in a chess game. I'm working with odd and even coordinates to know if the bishop can move or not, and it can move more than once to reach the final coordinate. 

My code does not work when it comes to the 'if' statement and it states "not all arguments converted during string formatting"...I've tried adding 'int' and stuff, but it's just not working..Help!!

 

Code:

a =1
while a==1:
    Numcas = int(input("How many cases do you have?: "))
    countcas = 1
    state = a = input('Enter the amount of columns and rows in your game: ')
    h = a.split(",")
    coltotal = int(h[0])    
    rowtotal = int(h[1])
    if (2<=coltotal<=1000 and 2<=rowtotal<=1000):
        while (countcas <= Numcas):
            question2 = 'Enter the starting position in the case #{}: '
            positionst = input(question2.format(countcas))
            position = positionst.split(",")
            colstart = int(position[0])
            rowstart = int(position[1])
            question4 = 'Enter the finishing position number in the case #{} '
            positionend= input(question4.format(countcas))
            positionen = positionend.split(",")
            colend = int(positionen[0])
            rowend = int(positionen[1])
            countcas+=1
            seqcount = 1
            if positionst[0] % 2 == 0 and positionst[1] % 2 == 0 and positionend[0] % 2 ==0 and positionend[1] % 2 ==0:
                print ("TRUE")
            if positionst[0] % 2 !=0 and positionst[1] % 2 !=0 and positionend[0] % 2 !=0 and positionend[1] % 2 !=0:
                print ("TRUE")
            if positionst[0] % 2 !=0 and positionst[1] % 2 ==0 and positionend[0] % 2 !=0 and positionend[1] % 2 ==0:
                print ("TRUE")
            if positionst[0] % 2 ==0 and positionst[1] % 2 !=0 and positionend[0] % 2 ==0 and positionend[1] % 2 !=0:
                print ("TRUE")
    else:
        print ("FALSE")
 

Link to post
Share on other sites
Posted · Best Answer

Don't forget to use the forum's code tag:

a =1
while a==1:
    Numcas = int(input("How many cases do you have?: "))
    countcas = 1
    state = a = input('Enter the amount of columns and rows in your game: ')
    h = a.split(",")
    coltotal = int(h[0])    
    rowtotal = int(h[1])
    if (2<=coltotal<=1000 and 2<=rowtotal<=1000):
        while (countcas <= Numcas):
            question2 = 'Enter the starting position in the case #{}: '
            positionst = input(question2.format(countcas))
            position = positionst.split(",")
            colstart = int(position[0])
            rowstart = int(position[1])
            question4 = 'Enter the finishing position number in the case #{} '
            positionend= input(question4.format(countcas))
            positionen = positionend.split(",")
            colend = int(positionen[0])
            rowend = int(positionen[1])
            countcas+=1
            seqcount = 1
            if positionst[0] % 2 == 0 and positionst[1] % 2 == 0 and positionend[0] % 2 ==0 and positionend[1] % 2 ==0:
                print ("TRUE")
            if positionst[0] % 2 !=0 and positionst[1] % 2 !=0 and positionend[0] % 2 !=0 and positionend[1] % 2 !=0:
                print ("TRUE")
            if positionst[0] % 2 !=0 and positionst[1] % 2 ==0 and positionend[0] % 2 !=0 and positionend[1] % 2 ==0:
                print ("TRUE")
            if positionst[0] % 2 ==0 and positionst[1] % 2 !=0 and positionend[0] % 2 ==0 and positionend[1] % 2 !=0:
                print ("TRUE")
    else:
        print ("FALSE")

 

The issue is that positionst and positionend are strings. This causes the % operator to be interpreted as string interpolation. You probably want to replace positionst[0] with colstart, positionst[1] with rowstart, etc... Those are your integers which will have % do the modulus operation like I think you are expecting.

 

Feel free to ask more questions.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×