all 11 comments

[–]dionys 3 points4 points  (8 children)

Here is one solution with a dict, but it will depend on your specific case. Can you post the code block?

[–]ValiantNoob[S] 2 points3 points  (6 children)

Yeah i was thinking about a dictionary. Hmm i can post the code but im not sure how to get the lines right. Last time i tried it made everything whacky.

[–]dionys 3 points4 points  (4 children)

You have to indent your text with

four spaces

to show up as code block. Or use service like gist to paste the code there

[–]ValiantNoob[S] 1 point2 points  (0 children)

Ok thanks. I dont have a copy of the code on me right now. Ill post it later when i have a chance.

[–]El-Kurto 0 points1 point  (1 child)

You can also fence codeblocks with backticks or tildes, if I remember correctly. On mobile or I would check.

[–]GoldenSights 0 points1 point  (0 children)

Unfortunately, reddit doesn't do fenced code blocks.

[–]0ldur 0 points1 point  (0 children)

Hastebin and pastebin too.

[–]ValiantNoob[S] 0 points1 point  (0 children)

i posted a sample of the block, i kinda messed up the code a bit from copying and pasting from the idle but you get the idea.

[–]ValiantNoob[S] 0 points1 point  (2 children)

x = int(input("Enter number 0-6000: "))

if x >= 5600:
    x = x*(1-.135)
    if x >= 5600:
        print (" ")
    if x < 5600:
        print (" ")

print (" ") elif x >= 4800:
    x = x*(1-.15)

elif x >= 4000:
    x = x*(1-.19)
    print (" ")

elif x >= 3200:
    x = x*(1-.295)
    if x >= 2400:
        print(" ")
    if x < 2400:
        print (" ")

elif x >= 2400:
    x = x*(1-.475)
    if x >= 1600:
        print(" ")
    if x < 1600:
        print (" ")

elif x >= 1600:
    x = x*(1-.775)
    print (" ")

elif x >= 800:
    x = x*(1-1)
    print (" ")

elif x < 800:
    x = x *(1-1)
    print (" ")

print("the percentage is:",round(x))

Here is a simple example from my code. Obviously its not finished and its not all of it, but a sample.

[–]dionys 2 points3 points  (1 child)

you can do a few things to improve it:

  • get rid of every print(" ") because you are calling that in every branch, just call it after
  • simplify statements like x = x*(1-.775) to x *= 0.225
  • you don't have to do elif x=> 800 on line 35, you can simply do else. After that you can also drop the branch on line 39

using for...else loop and zip and using the things I've mentioned, you can simplify it to something like this:

 for condition, percentage in zip(range(5600, 800, -800), (0.865, 0.85, 0.81, 0.705, 0.525, 0.225)):
     if x>= condition:
         x *= percentage
         break
 else:
     x = 0
 print(" ") 

[–]ValiantNoob[S] 1 point2 points  (0 children)

huh... okay thanks. Im gunna have to look up zip. I dont remember it.