Python error "SyntaxError: invalid syntax"

0 votes

I have a very simple python snippet:

from random import *

ip1 = input('Enter the N1 :')
ip2 = input('Enter the N2 :')

r = randint({0},{1}.format(ip1,ip2))

print r

But I get the following error:

File "index.py", line 6
    r = randint({0},{1}.format(i1,i2))
                  ^
SyntaxError: invalid syntax
Jul 5, 2019 in Python by Ruth
4,429 views

1 answer to this question.

0 votes

but i m getting this ouput:

Enter the N1 :1
Enter the N2 :3
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-52-89fb43b80989> in <module>()
      2 ip2 = input('Enter the N2 :')
      3 
----> 4 r = randint({2},{1}.format(ip1,ip2))
      5 
      6 print(r)

NameError: name 'randint' is not defined

answered Mar 20 by anonymous

Hey,

Please replace this line in your code with this:

r = randint({2},{1}.format(ip1,ip2))

to

r = randint({1},{3}.format(ip1,ip2))

I hope this error should go.

Related Questions In Python

0 votes
1 answer

'Syntax Error: invalid syntax' for no apparent reason

You're missing a close paren in this ...READ MORE

answered Aug 13, 2018 in Python by Priyaj
• 57,550 points
542 views
+1 vote
6 answers
0 votes
1 answer

What exactly is invalid syntax error?

please solve this error   def TakeImages():     Id=(text.get())   ...READ MORE

answered Jul 20 in Python by Prince kumar
282 views
0 votes
2 answers

%matplotlib inline SyntaxError: invalid syntax

I found a good solution to solve ...READ MORE

answered May 2 in Python by Edu
7,909 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,180 views
0 votes
0 answers
+4 votes
6 answers