New to Python and programming, following an exercise from a book.
The program should take a value and keep printing "to the power of '+1' " on every new line, using WHILE.
My code:
x = 2
def powerof2_table_while(victim):
line=1
result=victim**(line)
while result < 100:
""" want to write: 1.: 2 to the power of 1 is 2
2.: 2 to the power of 2 is 4
3.: 2 to the power of 3 is 8 """
print (line,".:\t", victim, "to the power of\t",line,"\t is", result)
line=line+1
return line
return line
resultat=powerof2_table_while(x)
print(resultat)
As well as the unnecessary return, you also never update the result variable, you should move this inside of the while loop to avoid the infinite loop and incorrect outputs
result=victim**(line) while result < 100:
should be
result=0 while result < 100: result=victim**(line)