0

Question on if statements with random integers

Do all intiger combinations have to be entered in every order or is there an easier way for the statement to take effect? For example: if int == 1 + 2 + 3 Print(“spam”) If the random integers happened to be say 3,2,1 or any combination of the 3 for that matter do we have to code for each possibility or is there a simpler way? Thank you in advance for you feedback :)

25th Jul 2018, 6:30 PM
Nate
Nate  - avatar
4 ответов
+ 4
Yes you can use the or operator The or operator can be used to seperate the three posibilities. Hey Nate please specify your language. is this python?
25th Jul 2018, 6:34 PM
Agent
Agent - avatar
+ 4
In python the or operator is known as “or” For example: if int == 1 + 2 + 3 or 2 + 3 + 1 ... print(“spam”) The “or” operator allows the if statement to be true if one of them is true There may be a simpler way that I do not know though. Learn about all the operators here: https://data-flair.training/blogs/python-operator/
25th Jul 2018, 6:45 PM
Agent
Agent - avatar
+ 2
The expression in your example will just be resolved to a value so it's just like typing 'if int == 6' If you wanted to compare on the actual ints used you would use some collection of objects, like a list or something
25th Jul 2018, 8:02 PM
Dan Walker
Dan Walker - avatar
+ 1
Yes its python! sorry about that
25th Jul 2018, 6:38 PM
Nate
Nate  - avatar