I am trying to learn basic python and I can't seem to be able to return values using a while loop. I am copying the syntax from guides I am reading but it doesn't seem to work when I run it. I may have a different version, I am not sure.
Anyways I was just messing around and got this code
def fact(x):
count = 1
sum = 0
while count <= x:
sum = count * sum
count + 1
else:
return sum
I don't even know if this correctly computes factorial, I don't care, I am just trying to get it to return a value. What is wrong? Why can't I use return? I am not sure what is wrong, when I replace return with
display,
it still doesn't work.
if,while,for,tryall have anelseclause.