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
2,863 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,530 points
286 views
0 votes
2 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

Python generates the error message you present ...READ MORE

answered Mar 14 in Python by Facts
• 140 points
47,810 views
0 votes
0 answers

What exactly is invalid syntax error?

Isnt it same as a nameerror, there ...READ MORE

Jun 12, 2019 in Python by Waseem
• 4,520 points
201 views
0 votes
1 answer
0 votes
0 answers

Python error "copyleaks.commandfailederror.CommandFailedError: Invalid login credentials."

I have the following code: ''' The MIT ...READ MORE

Aug 5, 2019 in Python by Aleesha
64 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 745 views
0 votes
0 answers
+4 votes
6 answers