python - Wrong output for given input -


here code:

#!/bin/python #gets id of player player = input()   first_moves = [int(i) in raw_input().split()] second_moves = [int(i) in raw_input().split()]  class calculate_bid(object):     def __init__(self,player,first_moves,second_moves):         self.mymove=[]         self.yourmove=[]         self.mycash=100         self.yourcash=100         self.pos=0         if player==1:             self.mymove.extend(first_moves)             self.yourmove.extend(second_moves)             self.tie=true         else:             self.mymove.extend(second_moves)             self.yourmove.extend(first_moves)             self.tie=false         self.x in range(len(self.mymove)):             if self.mymove[self.x]>self.yourmove[self.x]:                 self.mycash-=self.mymove[self.x]                 self.pos+=1             elif self.mymove<self.yourmove[self.x]:                 self.yourcash-=self.yourmove[self.x]                 self.pos+=1             else:                 if self.tie==true:                     self.mycash-=self.mymove[self.x]                     self.pos+=1                     self.tie=false                 else:                     self.yourcash-=self.yourmove[self.x]                     self.pos-=1                     self.tie=true         print self.mycash,self.yourcash 

why, if give input

2 4 15 8 8 

does print

92,-15 

?

note: don't think happens on computer only. same occurs when run 1 in hackerrank.

note: yourcash becomes 0 when second number (15 8) passes elif statement. before time, still 100. debugged before coming here.

note: tried this , this no luck.

update

this input:

2 4 15 7 8 8 6 

produces output:

92, -14 

i expected:

92, 79 

i have no idea code supposed do, presumably want subtract moves cash. that's inside loop in if , elif clause, , inside if section of else clause. then, in else / else section, set cash negative moves:

self.yourcash=-self.yourmove[self.x] 

while wanted write

self.yourcash -= self.yourmove[self.x] 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -