Scott Pickslay
Scott Pickslay

Reputation: 25

How to keep a rand var the same after the first time

So I have:

Num = random.randint(1,100)
Print(Num)
Num - 20
Print(Num)

And I want it to print the original rand number - 20, how wold I do this?

Upvotes: 0

Views: 35

Answers (2)

PhillipJacobs
PhillipJacobs

Reputation: 2490

@MrGeek is right. @ScottPickslay, just saying Num - 20 will calculate the answer you're looking for but you are not using that answer. By saying Num = num - 20, you are storing the answer of Num -20 back into Num.

Num = random.randint(1,100)
Print(Num) # Lets say this outputs the number 57
Num = Num - 20
Print(Num) # Then this will now be 37

Upvotes: 1

Djaouad
Djaouad

Reputation: 22776

Store the result of subtraction back to Num, don't just calculate it:

Num = Num - 20

Or:

Num -= 20

Upvotes: 0

Related Questions