code doesnt return anything - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: code doesnt return anything (/thread-27980.html) |
code doesnt return anything - ofrihemo - Jun-30-2020 [hey, im trying to get an odd number that the number that follows it will be divisible by 243 wrote the followring but i dont get any result, please help :) def answer3(): i = 1 while i < 100001: if i % 2 == 1: if (i + 1) % 243 == 0: return i i += 1 print(answer3()) RE: code doesnt return anything - Gribouillis - Jun-30-2020 What about print(2 * 243 - 1)It would be a shorter code. Your while loop never exits because the line i += 1 should be indented to become part of the while loop.
RE: code doesnt return anything - bowlofred - Jun-30-2020 Without seeing the formatting, I suspect that your indentation is incorrect. Please use the python tabs to enclose your code. RE: code doesnt return anything - ofrihemo - Jun-30-2020 (Jun-30-2020, 07:54 AM)Gribouillis Wrote: What about hey so how do you suggest putting it in the right indentation? thank you |