Program is not running in python [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 6 years ago.
Improve this question
My else and else if statements are not working. Every time it is showing incorrect syntax, whether I run it in shell or in file.
>>> num = 6
>>> if num == 4:
print("no is 4")
else:
SyntaxError: invalid syntax

Your indentation is bad :
if num == 4:
print("num is 4")
else:
print("num is not 4")

The following code will print True to the console.
num = 6
if num is 6:
print(True);
else:
print(False);

Related

SyntaxError File "import.py", line 14 [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
def division_title(initial):
n = initial.split()
if len(n) == 3 :
return n
else return [n[0],None,n[1]]
SyntaxError: invalid syntax
error message
You need to write it as follows.
def division_title(initial):
n = initial.split()
if len(n) == 3:
return n

Python Error "length is not defined" [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 7 years ago.
Improve this question
Please help me fix this code! When I run it it says that "length is not defined"
word1 = "sesquipedalian"
word2 = "sesquiannual"
length_of_word1 = length(word1)
length_of_word2 = length(word2)
test_number = 4298374272384726348726348726348234
if length_of_word1>length_of_word2:
test_number += length_of_word1%3
else:
test_number -= length_of_word1%3
print test_number
The Python function is len not length

Python indentation error in if statement [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 7 years ago.
Improve this question
I have a following trouble in Python.
sister_age = 15
brother_age = 12
if sisiter_age > brother_age:
print "sisiter is older"
else:
Error:
SyntaxError: invalid syntax
if sisiter_age > brother_age:
print "sisiter is older"
else:
File "<pyshell#5>", line 4
else:
^
IndentationError: unindent does not match any outer indentation level
No matter how many times I try to change the index, it shows an error.
Assuming there is something after the else statement, the else statement should be aligned with the if statement, not inside it.
Example -
if sisiter_age > brother_age:
print "sisiter is older"
else:
Also, if you do not have (or need) anything inside the else statement, you should just remove it.

if/elif/else statement in a while loop with python [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 8 years ago.
Improve this question
I'm new to python so this may be a beginner question. My 'else' statement in the code below gets a syntax error for a reason beyond my mind. I've looked up the syntax for it multiple times but I cannot find the error. This is my python code:
siteswap = input("Enter the siteswap you want to validate here:")
aantal_digits = len(siteswap)
i = 0
j = 1
while i != aantal_digits:
if (int(siteswap[i])+ (i + 1)) % aantal_digits == (int(siteswap[1:aantal_digits])+ (j + 1)) % aantal_digits:
print("This siteswap is invalid")
break
elif i != aantal_digits:
del (int(siteswap[i])
else:
print ("This siteswap is valid")
break
The else is highlighted and I get a "syntax error".
Your problem is
del (int(siteswap[i])
You are missing a closing parenthesis (but the parenthesis are unnecessary in the first place). Also, del int(siteswap[i]) will not work, because you cannot delete function calls: SyntaxError: can't delete function call
del siteswap[i]
will delete the actual item from your array.

Can't figure out "invalid syntax" message [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 8 years ago.
Improve this question
I've got this piece of code that is a part of a student database I'm making for class and I really can't determine why I'm getting invalid syntax on a particular line (line 3, userints).
def userints():
choices = int(input("Choose Student ID 1-6:")
userints = int(choices)
print (userints)
if userints == 1:
for line_number, line in enumerate(fileinput.input('init2.txt', inplace=1)):
if line_number == 1:
continue
else:
sys.stdout.write(line)
You forgot about second brace.
You forgot a ) on the previous line. It should be:
choices = int(input("Choose Student ID 1-6:"))

Categories