Home > other > This code is what's the problem, why the output explain impassability?
This code is what's the problem, why the output explain impassability?
Time:11-22
Import the random A=random. Randint (0, 10) if a> 2 the else 100 Print (a)
The code above idea is: to generate a random number when this number is greater than 2 output this number, otherwise the output 100 But the actual output is 100, no other results
No matter how many times the output, a value is 100, is a no less than or equal to 2? Strange
And when the code a> 2 to a> 1 Output results and is full of random Numbers, no matter how many times to refresh all have no output 100 Isn't there a less than or equal to 1? This code where there is the problem, why the output explain impassability?
CodePudding user response:
100 - "the else else a=100
CodePudding user response:
# if b value greater than 0, will be directly assigned to a, b or a set to 0 If a=b b> The else 0 0
A=a> 2? Random. Randint (0, 10) : 100, don't assign a direct comparison, it doesn't offer variable does not exist error?
CodePudding user response:
The code translation whose meaning is:
import random If a & gt; 2: A=random. Randint (0, 10) The else: A=100 Print (a)