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 6, 2019 in Python by Ruth
8,328 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, 2020 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

Why am I getting the syntax error SyntaxError invalid syntax in a line that contains fully valid syntax?

A "SyntaxError: invalid syntax" is a common ...READ MORE

answered Oct 18, 2023 in Python by anonymous
• 3,360 points
966 views
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
• 58,020 points
2,478 views
+2 votes
10 answers

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

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
409,375 views
0 votes
1 answer

What exactly is invalid syntax error?

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

answered Jul 20, 2020 in Python by Prince kumar
1,959 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,466 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,127 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP