0
Why is it not working
https://sololearn.com/compiler-playground/cCNqAvRd4yBp/?ref=app
8 ответов
+ 2
the if statement is placed at the back in comprehensions
print([a for a in range(1,b) if b%a==0])
+ 2
Thanks Bob_Li for helping me out. Now my code is ready and launched on the code playground.
+ 1
1. Describe what it is supposed to do
2. Read the error message
3. Read how to write the syntax correctly.
https://pythonguides.com/JUMP_LINK__&&__python__&&__JUMP_LINK-list-comprehension-using-if-else/
0
Maybe it comes from the explanation you said(in range)
0
I think the title should be this.
Factors of n
Plural, because 1 is the only int with a single int factor. Primes have two int factors, and zero has innumerable int factors.
Lowercase n because it implies a variable name, which implies any number that the user enters. N should be reserved for a class name.
0
Sadhv Nonu
your code inside the print function.(just for fun. it is horrible code, actually...😅)
print("Please enter a positive value for n" if (n := int(input()))<0 else "unlimited" if n==0 else f"The factors of {n} are:\n{[a for a in range(1, n + 1) if n%a == 0]}")
0
BTW I have just started learning 6 days ago so I think this is impressive (for me)
0
Sadhv Nonu ,
The code looks pretty good now. Two things: One, please adopt the convention of using four spaces per indentation level for readability. Two, your input validation condition and the conditional usage message don't match regarding zero.
if n < 0:
print("Please enter a positive value for n")
Since you do handle zero later, I suggest leaving the condition as is but changing the conditional usage message to something like this.
print("Please enter a non-negative integer for n.")
That way, they know they can enter zero.