Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code doesnt return anything
#1
[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())
Reply
#2
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.
Reply
#3
Without seeing the formatting, I suspect that your indentation is incorrect. Please use the python tabs to enclose your code.
Reply
#4
(Jun-30-2020, 07:54 AM)Gribouillis Wrote: 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.

hey so how do you suggest putting it in the right indentation? thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesnt chunk generation work? LotosProgramer 0 168 Jun-18-2021, 01:13 PM
Last Post: LotosProgramer
  if conditions in the for indentation doesnt work ? Sutsro 6 1,101 Jun-15-2021, 11:45 PM
Last Post: bowlofred
  Run the code for some stuff it does not return me why Anldra12 3 586 Apr-19-2021, 02:01 PM
Last Post: Anldra12
  I have two Same Code but One of them Doesnt Work beginner721 6 609 Jan-22-2021, 10:56 PM
Last Post: beginner721
  Pydoc documentation doesnt work Cosmosso 4 1,446 Dec-13-2019, 08:21 AM
Last Post: Cosmosso
  multiprocessing doesnt contain some modules(shared_memory) mike000 3 780 Oct-31-2019, 02:20 PM
Last Post: mike000
  BEGINNER: My calculator doesnt work iskov 5 1,076 Oct-09-2019, 07:45 AM
Last Post: buran
  Why this simple function doesnt work? blackknite 8 1,541 Jan-05-2019, 12:32 PM
Last Post: buran
  python code (embedded in Redshift) to return result of the query Mel 0 1,266 Aug-24-2018, 06:12 PM
Last Post: Mel
  why doesnt the while loop run? supermane 3 1,420 Aug-04-2018, 06:01 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020