[boxx][boxy] Syntax error [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am learning how to code in python with pygame using a book, so I am writing down the code. Yet when I run it, it gives me a syntax error on revealedBoxes[boxx][boxy] = True, I'm
^
not sure what the problem is. Thank you greatly if you could help!
Here is the code:
if boxx != None and Boxy != None:
if not revealedBoxes[boxx][boxy]:
drawHighlightBox(boxx, boxy)
if not revealedBoxes[boxx][boxy] and mouseClicked:
revealBoxesAnimation(mainBoard, [(boxx, boxy)]
revealedBoxes[boxx][boxy] = True

revealBoxesAnimation(mainBoard, [(boxx, boxy)]
You dropped a parenthesis here.

It is a valid statement
>>> revealedBoxes = [[True]]
>>> boxx, boxy = 0, 0
>>> revealedBoxes[boxx][boxy] = True
unless it is used as expression in while, if, ...:
>>> if revealedBoxes[boxx][boxy] = True: pass
File "<stdin>", line 1
if revealedBoxes[boxx][boxy] = True: pass
^
SyntaxError: invalid syntax
>>> while revealedBoxes[boxx][boxy] = True: pass
File "<stdin>", line 1
while revealedBoxes[boxx][boxy] = True: pass
^
SyntaxError: invalid syntax
Did you mean == ?
>>> if revealedBoxes[boxx][boxy] == True: pass
...
UPDATE
The code is missing ).
revealBoxesAnimation(mainBoard, [(boxx, boxy)] # <----
revealedBoxes[boxx][boxy] = True

Related

Anyone know how to fix illegal target for anotation [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 28 days ago.
Improve this question
was making some code and i ran into the error here is the code
import random
foo = ['sad', 'mad', 'happy ', 'inbetween', 'bored']
print("hello answer 1 or 2 or 3")
e = input(str)
if e == '1' : print("ok give me a sentence and ill tell you how i feel about it") ;a = input("please enter a sentence ") ;a == ('i hate you') :print(" i feel sad and mad that you hate me") ;a == ('I hate you') :print("i feel sad and mad that you hate me")
elif e == '2' :print("ok ill give you advice")
elif e == '3' :print("so you want to have a converstation")
else :print(" thats not an option")
A minimal reproducible example for this:
>>> if True: True: print('x')
...
File "<stdin>", line 1
SyntaxError: illegal target for annotation
The problem is that the second True was intended to be another if condition, but is instead just an expression. The parser treats : print('x') as a type annotation for True; but type annotations have to be applied to individual variable names, not expressions.
The specific error is only possible because print('x') is an expression, and thus a valid type annotation. If it were another kind of statement, this would cause a generic syntax error:
>>> if True: True: pass
File "<stdin>", line 1
if True: True: pass
^
SyntaxError: invalid syntax
Either way, there was a typo here - the second True: was meant to be if True:. However, this does not fix the problem by itself:
>>> if True: if True: pass
File "<stdin>", line 1
if True: if True: pass
^
SyntaxError: invalid syntax
It is not permitted to put multiple ifs on the same line; nor can elif and else be paired with the matching if on the same line:
>>> if True: pass; else: pass
File "<stdin>", line 1
if True: pass; else: pass
^
SyntaxError: invalid syntax
Putting multiple statements on a line - by using semicolons, and/or by putting the "suite" of an if etc. statement on the same line - is strongly discouraged in Python. It has multiple limitations, and makes the code much harder to read.
To make the example work, use indented blocks in the normal way:
if True:
if True:
pass

How to solve a TypeError: 'str' object is not callable? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
CODE:
import csv
import sys
def costo_camion(costo_camion): #def es la palabra reservada
suma = 0
f = open('Data/camion.csv', 'rt')
headers = next(f).split(',')
for line in f:
row = line.split(",")
costo = float(row[2]) * int(row[1])
suma = suma + costo
f.close()
return(suma)
if len(sys.argv) == 2:
costo_camion = sys.argv[1]
else:
costo_camion = 'Data/camion.csv'
suma = costo_camion('Data/camion.csv')
print('Costo Total', suma)
Line
else:
costo_camion = 'Data/camion.csv')
shows up the type error 'str' object is not callable (Python) and I don't know why, the code without this part:
if len(sys.argv) == 2 etc works just fine
thanks**
On line 3 in your code, you name your function costo_camion:
...
def costo_camion(costo_camion):
...
Then, on either line 15 or 17 you initialize a variable also named costo_camion:
...
costo_camion = sys.argv[1]
...
costo_camion = 'Data/camion.csv'
On line 19, you then try to call the function costo_camion:
...
suma = costo_camion('Data/camion.csv')
...
This will give you an error, because by this point no such function exists -- you have overwritten that name by using it for your variable.
My suggestion: re-name the variable on lines 15 and 17 to something like costo_camion_filepath. After that, you should no longer get this error. (You might have other issues with this code, but this particular error should be gone. :) )

Invalid syntaxt sum(list) >= 2 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I get an invalid syntax error at:
if sum(severe_symptoms_list) >= 2
I have set the values for the severe and moderate symptoms slots to True and False depending on what answer was given by the user to a YES/NO question. What have i done wrong ?
class ActionHowManySymptoms(Action):
def name(self) -> Text:
return "action_how_many_symptoms"
def run (self, dispatcher, tracker, domain):
severe_symptom1 = tracker.get_slot('severe_symptom_one')
severe_symptom2 = tracker.get_slot('severe_symptom_two')
severe_symptom3 = tracker.get_slot('severe_symptom_three')
severe_symptom4 = tracker.get_slot('severe_symptom_four')
moderate_symptom1 = tracker.get_slot('moderate_symptom_one')
moderate_symptom2 = tracker.get_slot('moderate_symptom_two')
moderate_symptom3 = tracker.get_slot('moderate_symptom_three')
moderate_symptom4 = tracker.get_slot('moderate_symptom_four')
severe_symptoms_list = [severe_symptom1, severe_symptom2, severe_symptom3, severe_symptom4]
moderate_symptoms_list = [moderate_symptom1, moderate_symptom2, moderate_symptom3, moderate_symptom4]
True = 1
if sum(severe_symptoms_list) >= 2
dispatcher.utter_response(response="utter_some_severe_symptoms", tracker)
elif sum(severe_symptoms_list) == 1
dispatcher.utter_response(response="utter_one_severe_symptoms", tracker)
else:
dispatcher.utter_response(response="utter_no_severe_symptoms", tracker)
if sum(moderate_symptoms_list) >= 2
dispatcher.utter_message(response="utter_some_moderate_symptoms")
elif sum(moderate_symptoms_list) == 1
dispatcher.utter_message(response="utter_one_moderate_symptoms")
else:
dispatcher.utter_message(response="utter_no_moderate_symptoms")
return[]
Try to code in a more decent presentable manner. It will help you in the long run
if (sum(severe_symptoms_list) >= 2):

global variable python, doesn't run [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I try to run this code in python 3.6
def Arrange(num):
global sec
sec=0
def Digit(nmb):
return nmb%10
def WithoutTheLastDigit(nmb2):
return nmb2//10
def IsEven(even):
if even%2==0:
return True
else:
return False
def AddDigit(number,dig):
number=number*10+dig
while num>0:
Digit(num)
if IsEven(Digit(num))==True:
sec=sec+AddDigit(sec,Digit(num))
WithoutTheLastDigit(num)
print(sec)
and it shows this error:
>>> Arrange(500)
Traceback (most recent call last):
File "", line 1, in
Arrange(500)
File "C:\Users\Yair\Desktop\hw3.py", line 56, in Arrange
sec=sec+AddDigit(sec,Digit(num))
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
Your problem is that the function AddDigit() returns None:
def AddDigit(number,dig):
number=number*10+dig
# this return None by default. mussing `return number`
while num>0:
Digit(num)
if IsEven(Digit(num))==True:
sec=sec+AddDigit(sec,Digit(num)) # This is 0 + None
WithoutTheLastDigit(num)
Note that you code can be simplify greatly with a few things. I didn't change the logic, so you might have some errors here.
def Digit(number):
return number % 10
def WithoutTheLastDigit(number):
return number // 10
def IsEven(number):
return number % 2 == 0:
def AddDigit(number, digit):
return number*10 + digit
while number > 0:
digit = Digit(number)
if IsEven(digit):
sec += AddDigit(sec, digit)
print(sec)

max() arg is an empty sequence [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have written a program for Radix Sort in Python. But when I execute the code I get following error message max() arg is an empty sequence.
Here is my code:
class RadixSort:
num=0
array=[]
def getData(self):
print 'Enter the number of elements you want to enter: '
num=int(input())
print 'Now enter the elements: '
for i in range(0,self.num):
print 'Element ',i+1,': '
value=int(input())
self.array.append(value)
def radixSort(self):
bin=[[],[],[],[],[],[],[],[],[],[]]
r=1
m=max(self.array)
while m>r:
for ele in self.array:
bin[(ele/r)%10].append(ele)
r=r*10
self.array=[]
for i in range(10):
self.array.extend(bin[i])
bin[i]=[]
def displayArray(self):
print ''
for ele in self.array:
print ele
RObject=RadixSort()
RObject.getData()
RObject.radixSort()
RObject.displayArray()
I get this error before entering values in array. How can I solve this?
I think you should replace:
num = int(input())
to
self.num = int(input())
Not superfluous will be to check that the array is not empty:
m = max(self.array) if self.array else 0
You should show the complete traceback. When I run your code I get this:
Enter the number of elements you want to enter:
3
Now enter the elements:
Traceback (most recent call last):
File "radix.py", line 35, in <module>
RObject.radixSort()
File "radix.py", line 17, in radixSort
m=max(self.array)
ValueError: max() arg is an empty sequence
so m=max(self.array) fails because you can't do a max function on an object that doesn't exist. You need to have an init method to create self.array
Why are you using input and not raw_input? You are using python 2.7

Categories