Having trouble with python3 print syntax [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 3 months ago.
Improve this question
I've started to learn python about 4 days ago. To practice, I've decided to make a program that calculates combinations.
Here is the code:
print('Insert values for your combination (Cp,n)')
def combin(exemplo):
print('insert p value')
p = int(input())
print('insert n value')
n = int(input())
exemplo = [p,n]
#"fator" is a function defined earlier in the program. It basically calculates the factorial of a number
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))
print(res)
teste = []
combin(teste)
After running this, the following error has ocurred:
print(res)
^
SyntaxError: invalid syntax
>>>
However, I can't see what I'm doing wrong here. I figured that I probably would have problems with the math and the functions, but I can't figure out what's up with the syntax in this case.

Hey nothing to worry about, its just a typo with missing parenthesis
hope you find the solution :)
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))

Hey in the following line:
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))
you are missing a closing bracket.

You didn't close all of your parenthesis in the res line. Try this:
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1]))*fator(exemplo[1]))

Related

Python question: My function isn't running, using the input values I have set. Python 3.9 [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 5 months ago.
Improve this question
I am trying to create a function to convert DMS to DD. My function isn't running utilizing the import answer I provide. I an new to python, any assistance would be great.
import math
def d_m_s(d,m,s):
d = int(d)
m = int(m)
s = int(s)
dd = d + m/60 + s/3600
print(dd)
d,m,s = input("Enter degrees, minutes, and seconds:").split(',')
print(type(d))
You have called the type() function in your print statement. This will just tell you if d is a string, int, float, etc. In order to print "d", just use print(d).
However, in order to print the DD conversion, instead of ending with a print statement, you can replace the last line with d_m_s(d,m,s)
Hope this helps!

Why is the "else" line giving an invalid syntax error even with proper indentation and syntax? [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 1 year ago.
Improve this question
I know this question has been asked many many times on here, but I seem to not have the same issues as others. I continually get "syntax error invalid syntax else", but do not know why this is. I seem to have everything properly indented and colons after the else statement. Any help would be much appreciated. Thanks
def normalization (fname, attr, normType):
result = {}
df = pd.read_csv(fname)
targ = list(df[df.columns[attr]])
scaler = MinMaxScaler()
df["minmax"] = scaler.fit.transform(df[[df.columns[attr]]])
df["zscore"] = ((df[[df.columns[attr]]]) - (df[[df.columns[attr.mean()]]]))/(df[[df.columns[attr.std(ddof=1)]]])
if normType == "min_max":
result = dict(zip(targ, df.minmax.values.tolist())
else:
result = dict(zip(targ, df.zscore.values.tolist())
return result
result = dict(zip(targ, df.minmax.values.tolist()))
The conversion to dictionary line in the if condition is missing one bracket.

Python If(and) statement syntax error [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'm trying to make a simple console game in Python 2.7, where the user gets a dilemma and makes a decision by typing the number correlating to the option he wants to choose. This question is the main menu.
s = raw_input("Enter a number in the range 1 to %s\n> " % v
if (is_number(s) and s in q):
return s
I'm getting a "SyntaxError: Invalid syntax" from the if (is_number(s) and s in q) statemet when trying to run the program. It was working fine before i added the question.
This is my first real program.
You're missing a parentheses on the previous line:
s = raw_input("Enter a number in the range 1 to %s\n> " % v
# here--^

Python - TypeError: string indices must be integers [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 9 years ago.
Improve this question
For some reason this piece of script is returning the error: "TypeError: string indices must be integers"; and I cannot see what's wrong. Am I being stupid and overlooking an obvious mistake here? I can't see one for the life of me!
terms = {"ALU":"Arithmetic Logic Unit"}
term = input("Type in a term you wish to see: ")
if term in terms:
definition = term[terms]
sentence = term + " - " + definition
print(sentence)
else:
print("Term doesn't exist.")
I think you want it this way: definition = terms[term]
This line definition = term[terms] is trying to get a character out of the string term. You probably just typoed, and want
definition = terms[term]
^ here, reference the dict, not the string
You are indexing the string term instead of the dictionary terms. Try:
definition = terms[term]
You accidentally swapped the variables. Change this:
definition = term[terms]
To this:
definition = terms[term]

INVALID SYNTAX ERROR for 'else' statement in 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 2 years ago.
Improve this question
I am trying to write a quicksort program in python, however I'm getting an invalid syntax error at else statement in the second last line below:
import random
n=int(raw_input("Enter the size of the list: ")) # size of the list
intlist = [0]*n
for num in range(n):
intlist[num]=random.randint(0,10*n)
pivot=random.choice(intlist)
list_1=[] # list of elements smaller than pivot
list_2=[] # list of elements greater than pivot
for num in range(n):
if num<=pivot:
list_1.append(num)
else
list_2.append(num)
This is not a complete program as I am still writing.
add a colon after the else so that it looks like else:. and pick up a good tutorial ;)
Looks like you need a ':' after "else".

Categories

Resources