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
7,224 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

'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,060 points
1,643 views
+1 vote
10 answers

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

Just for the record: >>> int('55063.000000') Traceback (most recent ...READ MORE

answered Aug 17, 2020 in Python by pakainfo
• 200 points
355,615 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
759 views
0 votes
2 answers

%matplotlib inline SyntaxError: invalid syntax

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

answered May 2, 2020 in Python by Edu
16,910 views
0 votes
1 answer

Python error "TypeError: 'encoding' is an invalid keyword argument for this function"

Trying using the io module for this ...READ MORE

answered Aug 2, 2019 in Python by Vaishali

edited Oct 7, 2021 by Sarfaraz 10,243 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 2,758 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
2,057 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP