How to change these numbers in list ....???? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to change these numbers in list ....????

https://sololearn.com/compiler-playground/c2o4g3oTuyBa/?ref=app In this code I want to convert these prime numbers into a list ...🧐🧐🧐✅✅ Pls help me....

19th Jan 2024, 1:42 PM
Shivi Kushwaha
Shivi Kushwaha - avatar
4 Answers
+ 2
Shivi Kushwaha , Adding to what Ognjen Fatić wrote. The append method changes the list in place, so the syntax doesn't require an assignment. For example. a = list() # empty list a.append(47) a.append("Ronin") print(a) # [47, 'Ronin'] print(*a) # 47 Ronin All list methods: https://docs.python.org/3/tutorial/datastructures.html#more-on-lists
19th Jan 2024, 4:57 PM
Rain
Rain - avatar
+ 4
You can declare an empty list at the beginning of your code and on line 13 instead of printing num you can append num to your empty list. In the end you can print your list.
19th Jan 2024, 1:49 PM
Ognjen Fatić
Ognjen Fatić - avatar
+ 1
x= 30 y= 50 primes = [] for num in range(x, y+ 1): # all prime numbers are greater than x and less than or equal to y if num > 1: for i in range(2, num): if (num % i) == 0: break else: primes.append(num) print(primes)
20th Jan 2024, 2:27 AM
Bob_Li
Bob_Li - avatar
+ 1
Okkk!!.... thanks for everyone👍👍
20th Jan 2024, 2:47 AM
Shivi Kushwaha
Shivi Kushwaha - avatar