jeudi 28 janvier 2021

Printing the wrong value in python for an if statement [duplicate]

So I want to test a logic, this is not the final code that will go into production.

I have made the following for debugging(not for production):

def percentagep():
 a = 720
 b = 1000
 c = a/b
 d = c*100
 a1 = 500
 b1 = 1000
 c1 = a1/b1
 d1 = c1*100
 print(str(d))
 print(str(d1))

 
 r = range(5,10)
 r1 = range(11,15)
 r2 = range(16,20)
 r3 = range(21,25)
 r4 = range(26,30)
 r5 = range(31,35)
 r6 = range(36,40)
 r7 = range(41,45)
 r8 = range(46,50)
 r9 = range(51,55)
 r10 = range(56,60)
 r11 = range(61,65)
 r12 = range(66,70)
 r13 = range(71,75)
 r14 = range(76,80)
 r15 = range(81,85)
 r16 = range(86,90)
 r17 = range(91,95)
 r18 = range(96,100)
 if d in r:
    print('90')
 elif d in r1:
    print('85')
 elif d in r2:
    print('80')
 elif d in r3:
    print('75')
 elif d in r4:
    print('70')
 elif d in r5:
    print('65')
 elif d in r6:
    print('60')
 elif d in r7:
    print('55')
 elif d in r8:
    print('50')
 elif d in r9:
    print('45')
 elif d in r10:
    print('40')
 elif d in r11:
    print('35')
 elif d in r12:
    print('30')
 elif d in r13:
    print('25')
 elif d in r14:
    print('20')
 elif d in r15:
    print('15')
 elif d in r16:
    print('10')
 elif d in r17:
    print('5')
 elif d in r18:
    print('0')


 if d1 in r:
    print('90')
 elif d1 in r1:
    print('85')
 elif d1 in r2:
    print('80')
 elif d1 in r3:
    print('75')
 elif d1 in r4:
    print('70')
 elif d1 in r5:
    print('65')
 elif d1 in r6:
    print('60')
 elif d1 in r7:
    print('55')
 elif d1 in r8:
    print('50')
 elif d1 in r9:
    print('45')
 elif d1 in r10:
    print('40')
 elif d1 in r11:
    print('35')
 elif d1 in r12:
    print('30')
 elif d1 in r13:
    print('25')
 elif d1 in r14:
    print('20')
 elif d1 in r15:
    print('15')
 elif d1 in r16:
    print('10')
 elif d1 in r17:
    print('5')
 elif d1 in r18:
    print('0')



    percentagep()

For d will print 25 and it's ok because d is 72 and 72 is between 71 and 75.

  1. Why it doesn't print anything for d1?
  2. If a=1000 and b=1000 so d=100, why it doesn't print anything?

Aucun commentaire:

Enregistrer un commentaire