+ 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....
4 Respuestas
+ 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
+ 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.
+ 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)
+ 1
Okkk!!.... thanks for everyone👍👍