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:"))
Related
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 am new here learning Python. I have a problem of syntax but I am unable to fix it. Can someone please help ?
Here's the code:
def saisie(the_list)
input_string = input("Enter a list elements separated by space (max 6)\n")
the_list = input_string.split()
if len(the_list) > 6:
return '{}Error'
return '{}Error'
else:
return f'user list: {the_list}'
saisie(liste)
and I got this error :
File "c:/Users/Jay/Desktop/Python Exercices/app/tribulle.py", line 6
def saisie(the_list)
^
SyntaxError: invalid syntax
Which is the invalid syntax, what should I change please?
When defining a function, you must put a colon at the end of the "def saisie(the_list)" or else Python will not know that you are defining a function.
You are missing the colon, it should be
def saisie(the_list):
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 calculate_money_made(**trips):
total_money_made = 0
for trip_id, trip from trips.items():
trip_revenue = trip.cost - trip.driver.cost
total_money_made += trip_revenue
return total_money_made
gives an error! cannot figure out
File "script.py", line 41
for trip_id, trip from trips.items():
^
SyntaxError: invalid syntax
Change "from" to "in"
for trip_id, trip in trip.items():
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
So, I'm trying to make an easter egg in my calculator program, where if you type my friend johns name in, it prints nerd, but I keep getting invalid syntax on the line the if statement starts. here's what the code looks like:
x = input(' ')
if x = John:
print nerd
else:
print x
please keep in mind i'm using python 2.7, not 3. when I googled it, I only got answers that worked in 3.
x = raw_input('enter name ')
if x == 'John':
print 'nerd'
else:
print x
You are doing an assignment, but you need == to check for equality
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
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
Every time I try to run these first 2 lines in python, it says:
SyntaxError: invalid syntax
And highlights the name of the variable I'm trying to define (Yname).
These are the lines I'm trying to run:
print("Hello what's your name?")\
Yname = input("your name:")
It is because of the \ at the end of the first line.
in Python \ is the line continuation character. Python is trying to parse this as
print("Hello what's your name?")Yname = input("your name:")