-1

We provide you with a number N.

Create a list then, using a loop, populate the list with N elements. Set each list element to the index multiplied by 10.

The easiest way would probably be to change len(numbers) to equal the value of N, but I know I can't do it through brute force, i.e.: len(numbers) = N. Here is what I have tried.

import sys    
N= int(sys.argv[1])    
numbers = [1, 2, 3, 4, 5]
Anurag A S
  • 725
  • 10
  • 23
  • 2
    Maybe looking at python's [`range`](https://docs.python.org/3/library/functions.html#func-range) would be a good place to start. – Mark Jul 25 '19 at 05:13
  • 2
    Possible duplicate of [Create an empty list in python with certain size](https://stackoverflow.com/questions/10712002/create-an-empty-list-in-python-with-certain-size) – brentertainer Jul 25 '19 at 05:14
  • Welcome to StackOverflow. SO is not a code-writing service. Please provide what you have tried and what went wrong. – Chris Jul 25 '19 at 05:14

3 Answers3

0

what about:

numbers = [n * 10 for n in range(N)]
kederrac
  • 16,819
  • 6
  • 32
  • 55
0

You could try using list comprehension.

>>> n = 5                                                                                                               
>>> numbers = [i*10 for i in range(1,n+1)]                                                                              
>>> numbers                                                                                                             
[10, 20, 30, 40, 50]                                                                                                    
>>>

This could work.

Anurag A S
  • 725
  • 10
  • 23
0
N=100
numbers = [(i+1)*10 for i in range(N)]
print(numbers)

Try this

J CHEN
  • 494
  • 3
  • 9