Hi all, can anyone help me with writting the code that does:

n=5
for i in range(0,n,1):
    answer=a*i    #a is an array,say([2,3,4])
    return answer

basically I want compute a*i and return answers when i=0,1,2,3,4 ,and the answer should be a 3*n matrix, first row is when i=0, second row is when i=1, and so on.....
thanks aloooot in advance

Member Avatar for leegeorg07

I assume you learnt a different language first?

you don't need the '1' you put in there, I would use:

n=5
for a in range(n+1):
  for b in range(n+1):
    print a,b

it produces:

0 0
0 1
0 2
0 3
0 4
0 5
1 0
1 1
1 2
1 3
1 4
1 5
2 0
2 1
2 2
2 3
2 4
2 5
3 0
3 1
3 2
3 3
3 4
3 5
4 0
4 1
4 2
4 3
4 4
4 5
5 0
5 1
5 2
5 3
5 4
5 5

and I will leave you to figure out how and why

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.