How to use for loops and assign values to array

asked 4 years ago

anonymous user

Anonymous

updated 4 years ago

x = 3 z = IncreasingArrays() z = x.binary()

for i in range(x): if z[i] == 1: print(' ', 2^i) # Not printing here

I'm unable to print the 3rd line it always says space indent etc.

How to solve this? Also please help me how to assign values in an array in for loop

Also binary values I should store in array how to??

I'm new please help

I'm using this only on sagemath cell server online

Thanks

Preview: (hide)

Comments

Could you please provide your code ? To format it, you select the code and click on the 101011 button on top of the edition box.

tmonteil gravatar imagetmonteil ( 4 years ago )

Thanks for the response

x=3 z=IncreasingArrays() z=x.binary()

for i in range(x): if(z[i]==1): print (' ',2^i) #Not printing here

I want to print if binary value is 1 And raise it to power 2

For loop isn't printing print statement also Please help me with these for loops and also how to store values in an array

in C I go

int a[6]; for(i=2;i<=5;i++) { a[i]=1; }

Here like this in C, array values are set.

How to do the same in sage please help

Rama gravatar imageRama ( 4 years ago )

Still no indentation. We can't help you without it : In Python, whitespace (indentation, line feeds) is syntactic.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 4 years ago )

Now please check again I have written the program.

Also how to initiate elements in array, please tell me

Rama gravatar imageRama ( 4 years ago )