syntax-error

Prompt JavaScript If Else Unexpected Token else

流过昼夜 提交于 2019-12-07 01:27:25
问题 I'm teaching myself JavaScript using Code Academy and I'm trying to make some simple code so that when prompt asks a question, the user reply gives a response. example. prompt says "what's your favourite colour?" user says "blue" response "that's the same colour as the sky!" But when I try to add different options, I get Syntax error: unexpected token else. I tried making it so that if I asked a question, the reply gets a response but anything else gets a response. Here's the code. prompt(

Creating a list with >255 elements

梦想与她 提交于 2019-12-06 19:36:44
问题 Ok, so I'm writing some python code (I don't write python much, I'm more used to java and C). Anyway, so I have collection of integer literals I need to store. (Ideally >10,000 of them, currently I've only got 1000 of them) I would have liked to be accessing the literals by file IO, or by accessing there source API, but that is disallowed. And not ontopic anyway. So I have the literals put into a list: src=list(0,1,2,2,2,0,1,2,... ,2,1,2,1,1,0,2,1) #some code that uses the src But when I try

Questions about a tic-tac-toe program I am writing

这一生的挚爱 提交于 2019-12-06 16:44:43
I am making a tic-tac-toe program in python. I have two questions: How to create a trick to terminate the move() when we have created a diagonal or a line(xxx or OOO) in the game. In my program some error is occurring::in line 28::(UnboundLocalError: local variable 'stop' referenced before assignment) My code is:: import random board = {"top-l":" ","top-m":" ","top-r":" ","mid-l":" ","mid-m":" ","mid-r":" ","low-l":" ","low-m":" ","low-r":" "} def print_board(board): print( board["top-l"] + "|" + board["top-m"] + "|" + board["top-r"]) print("--------") print( board["mid-l"] + "|" + board["mid

Python: Making a class to use complex numbers

China☆狼群 提交于 2019-12-06 16:26:32
问题 I am currently trying to write a program that deals with complex numbers. I have to use classes and methods. I am trying to be able to add, subtract, multiply etc., complex numbers, as well as compare them to one another. I think I have gotten a good start but have some issues. I have started each method, and I think I just need to fill in the gaps. In the method, I used self.x as a placeholder. I'm not really sure what goes there. First off, the program needs to create it's own complex

The equivalent C code of a valid C++ code with a While loop does not compile

梦想的初衷 提交于 2019-12-06 16:26:13
问题 The following code containing a while loop compiles in C++. #include <iostream> using namespace std; int main() { while (int i = 5) { break; } return 0; } However, the following equivalent C code results in an error if compiled in C: #include <stdio.h> int main() { while (int i = 5) { break; } return 0; } Compiler output: > prog.c: In function 'main': prog.c:5:9: error: expected expression > before 'int' while (int i = 5)prog.c: In function 'main': > prog.c:5:9: error: expected expression

Jython @property SyntaxError: mismatched input '' expecting CLASS

牧云@^-^@ 提交于 2019-12-06 15:39:43
I tried to run this example from the docs in the Jython interpreter: http://www.jython.org/docs/library/functions.html class C(object): def __init__(self): self._x = None @property def x(self): """I'm the 'x' property.""" return self._x @x.setter def x(self, value): self._x = value @x.deleter def x(self): del self._x Just entering the first 4 lines (up to and including @property ) yields a SyntaxError: >>> class C(object): ... def __init__(self): ... self._x = None ... @property File "<stdin>", line 4 @property ^ SyntaxError: mismatched input '' expecting CLASS Update: I am on Jython 2.5.2

Python ast.literal_eval on dictionary string not working (SyntaxError: invalid syntax)

半世苍凉 提交于 2019-12-06 14:34:03
问题 I am trying to process a dataset with JSON data. However, the data have been written on a file without being parsed. That means that a python dictionary is written in the file as a string instead of a JSON object as a string. I've found a module (AST) that will do the job to convert the string to a dictionary again using the ast.literal_eval function. However, I am getting a very strange error in some of the instances: The code reads from a text file and apply the following to each line: ast

leading zeros in python [duplicate]

泪湿孤枕 提交于 2019-12-06 14:03:55
This question already has answers here : What do numbers starting with 0 mean in python? (9 answers) Closed 6 years ago . Python seems to be able to accept leading zeros for any number except 08 or 09. For instance, a = 04 works in the interpreter but a = 08 returns SyntaxError: invalid token I'm using python 2.7.3 on OSX, and others have been able to duplicate the error. What gives? Numbers with a leading zero in them are interpreted as octal, where the digits 8 and 9 don't exist. It's worse in Python 3, leading zeros are a syntax error no matter which digits you use. See What’s New In Python

Haskell list comprehension for finding primes

血红的双手。 提交于 2019-12-06 10:51:54
I'm trying to find all the primes less than some integer n as concisely as possible, using list comprehensions. I'm learning Haskell, and this is just an exercise. I'd like to write something like: isqrt :: Integral a => a -> a isqrt = floor . sqrt . fromIntegral primes :: Integral a => a -> [a] primes n = [i | i <- [1,3..n], mod i k /= 0 | k <- primes (isqrt i)] which of course doesn't work. Is there a way to have a list comprehension inside a list comprehension? Here is the error I'm getting: exercise-99-1.hs:138:39: Not in scope: `k' exercise-99-1.hs:138:46: Illegal parallel list

Required: Variable Found: Value

走远了吗. 提交于 2019-12-06 08:19:48
public static int biggestArrayGap(int []a, int n) { int biggestGap = Math.abs(a[1]-a[0]); for (int i=1; i<n-1; i++) { if (Math.abs(a[i]-a[i-1]) > biggestGap) Math.abs(a[i]-a[i-1]) = biggestGap; } return biggestGap; } For some reason, the second line in the if statement is returning as unexpected type– required: variable found: value. I tried == and that obviously didn't work. Any insight? You switched the operands in your assign statement. Switch this Math.abs(a[i]-a[i-1]) = biggestGap; to this biggestGap = Math.abs(a[i]-a[i-1]); Math.abs(a[i]-a[i-1]) returns just an int value (no variable