+ 1

why output like this [4, 6, 8, 9]

f=open("num.txt","w") f.write("1\n2\n3\n4\n5\n6\n7\n8\n9\n10") f.close() f=open("num.txt","r") m=0 r=f.read() l=r.split("\n") leng=len(l) p=[] c=[] def prime(num): flag = False if num > 1: for i in range(2, num): if (num % i) == 0: flag = True if flag and num>1: c.append(num) if not flag and num>1: p.append(num) while m<leng: num=int((l)[m]) prime(m) m=m+1 print("Numbers:\n",r) print("Prime numbers: ",p) print("Composite Numbers: ",c) why output(composite number) has no first number and last number?(1 and 10)

29th Mar 2023, 6:13 AM
Muhammed Rishad. K
Muhammed Rishad. K - avatar
1 Antwort
+ 8
1 ist not > 1 . so no condition matches please try else-statement instead of if not or try not(flag and num > 1) 10 is not < leng and will not be regarded while m <= leng will do it.
29th Mar 2023, 7:07 AM
Oma Falk
Oma Falk - avatar