def square(x):
x = 2**x
x = 2.0
while x < 100.0:
print x, '\t', square(x)
x = square(x)
I tried to print. But it won't print. What I actually wanted were the squares of 2. But it won't be printing? What am I doing wrong?
def square(x):
x = 2**x
x = 2.0
while x < 100.0:
print x, '\t', square(x)
x = square(x)
I tried to print. But it won't print. What I actually wanted were the squares of 2. But it won't be printing? What am I doing wrong?
you should return a value.
def square(x):
y = 2**x
return y
and increment x value.
while x < 100.0:
print x, '\t', square(x)
x += increment_value
I think square(x) = x^2 not 2^x
?
You can even make it look like
while i<100.0:
print x**2,"\t"
i+=1#If you increment i by one
The mistake you made is not returning the value Add a statement return sqvalue where sqvalue is the squared of the value you give as input.
def square(int x):
sqvalue=x**2
return sqvalue
or write it in a single line function
def square(int x):
return x**2
I suggest you may take a look at lambda(anonymous functions) for these simple tasks.