Python Forum
Am i doing something wrong with this piece of code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Am i doing something wrong with this piece of code
#2
I'm guessing because theres no remainder.
for k in range(j,j+3):
Starts at index 3 and ends on 6.
6%3 = 0
You could try checking it first and assign 3 if it has no remainder.
There's probably a better way of doing it but this should work.
kdisplay= k%3 if (k%3) else 3

for i in range(1, 4):
    for j in range(i, i + 3):
        if (j > 3):
            jdisplay = j % 3
 
        else:
            jdisplay = j
        for k in range(j,j+3):
            kdisplay= k%3 if (k%3) else 3
            print(i,jdisplay,kdisplay)
Reply


Messages In This Thread
RE: Am i doing something wrong with this piece of code - by JustaNoOb - Mar-02-2018, 05:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 578 Nov-07-2023, 04:32 PM
Last Post: snippsat
  An unexplainable error in .format statement - but only in a larger piece of code? ToniE 4 805 Sep-05-2023, 12:50 PM
Last Post: ToniE
  First piece of code Bearwulf 2 842 Aug-02-2023, 04:03 PM
Last Post: deanhystad
  Something wrong with my code FabianPruitt 5 968 Jul-03-2023, 10:55 PM
Last Post: Pedroski55
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,739 Mar-27-2023, 07:38 AM
Last Post: buran
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,390 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 2,012 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,815 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Understanding a piece of code Michael1 4 1,536 Jan-20-2022, 07:14 PM
Last Post: Michael1
  Wrong code in Python exercise MaartenRo 2 1,601 Jan-01-2022, 04:12 PM
Last Post: MaartenRo

Forum Jump:

User Panel Messages

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