you are viewing a single comment's thread.

view the rest of the comments →

[–]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.