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 :)
4 ответов
+ 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/
+ 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
+ 1
Yes its python! sorry about that