Click here to Skip to main content
15,915,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make function that will make a random subtraction problem.

so I have
ran1 = randint(0,20)
ran2 = randint(0,20)
print('What is ' + str(ran1) + ' - ' + str(ran2) + '?')

How can I make ran2 be less than ran1?
Posted
Comments
[no name] 8-Oct-15 1:09am    
You can try lie below:

int ran1 = randint(0,20);
int ran2 = randint(0,ran1);

or

int ran1 = randint(0,10);
int ran2 = randint(10,20);

You could use randint in this manner -
VB
ran1 = randint(0,10)
ran2 = randint(10,20)

Alternately, use randrange - randRange[^].
 
Share this answer
 
Whichever number is greater, subtract the other number from it ;)
You can do something like this,
Python
ran1 = randint(0,20)
ran2 = randint(0,20)
if ran1 > ran2
    print('What is ' + str(ran1) + ' - ' + str(ran2) + '?')
elif ran2 > ran1
    print('What is ' + str(ran2) + ' - ' + str(ran1) + '?')


-KR
 
Share this answer
 
Comments
[no name] 8-Oct-15 1:15am    
I can't believe I didn't think of that!!! :)
Krunal Rohit 8-Oct-15 1:23am    
Happens to us all :laugh:

-KR

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900