Home>

I'm making an auction-style program for studying.
The bidders are Mr. A and Mr. B.

A's bid unit 10 yen
B's bid unit 20 yen
I would like to give out the winning bid and the winning bidder.
The successful bid order is Mr. A → Mr. B.

There are times when the highest bidder is displayed incorrectly.
I thought a lot, but I don't know how to display the successful bidder correctly.
kakaku = starting price
a_jougen = A's highest bid price
b_jougen = B's highest bid price.
Thank you.

total = kakaku
num = 0
while True:
    num + = 1
    if total + 10<= a_jougen:
        total + = 10
    if total +10>a_jougen:
        break
    num + = 1
    if total + 20<= b_jougen:
        total + = 20
    if total + 20>b_jougen:
        break

if num% 2 == 1:
    print ('A')
else:
    print ('B')
print (total)
  • Answer # 1

    code
    total = kakaku
    num = 0
    while True:
        if total + 10<= a_jougen:
            total + = 10
            num + = 1
        elif total + 10>a_jougen:
            break
        if total + 20<= b_jougen:
            total + = 20
            num + = 1
        elif total + 20>b_jougen:
            break
    if num% 2 == 1:
        print ('A')
    else:
        print ('B')
    print (total)