10th Jan 2024, 12:30 PM
Sadhv Nonu
Sadhv Nonu - avatar
8 odpowiedzi
+ 2
the if statement is placed at the back in comprehensions print([a for a in range(1,b) if b%a==0])
10th Jan 2024, 9:19 PM
Bob_Li
Bob_Li - avatar
+ 2
Thanks Bob_Li for helping me out. Now my code is ready and launched on the code playground.
11th Jan 2024, 8:55 AM
Sadhv Nonu
Sadhv Nonu - avatar
+ 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/
10th Jan 2024, 1:07 PM
Lisa
Lisa - avatar
0
Maybe it comes from the explanation you said(in range)
10th Jan 2024, 4:44 PM
Fateme Biglari
Fateme Biglari - avatar
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.
10th Jan 2024, 7:24 PM
Rain
Rain - avatar
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]}")
12th Jan 2024, 12:21 PM
Bob_Li
Bob_Li - avatar
0
BTW I have just started learning 6 days ago so I think this is impressive (for me)
13th Jan 2024, 7:12 AM
Sadhv Nonu
Sadhv Nonu - avatar
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.
13th Jan 2024, 4:03 PM
Rain
Rain - avatar