Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

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

1 Answer

0 votes
by (25.1k points)

The reason you are getting this error is because you are calling the randint function incorrectly, you are passing a set containing  0 and another set containing 1 and calling format method, which can only be called on a string. To use randint method you need to pass two integers as the beginning and end of the range in which you wish to get a random number. For example:

from random import *

ip1 = input('Enter the N1 :')

ip2 = input('Enter the N2 :')

r = randint(ip1,ip2)

print r

And in case you wish to print the range on screen you can do it this way:

print "{0}, {1}".format(ip1, ip2)

Related questions

0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...