2017年12月23日 星期六

a039: 公平的戰役(EOF版)

a039: 公平的戰役(EOF版)

'''輸入說明:
輸入資料有多組,每一組有兩個正整數 A、B,代表 A、 B兩方的兵力。
當沒有資料可以輸入的時候,結束此程式。
'''

A=[]
B=[]

print("輸入資料有多組,每一組有兩個正整數 A、B,代表 A、 B兩方的兵力。")
print("當沒有資料可以輸入的時候,結束此程式。")
phrase1 = None
phrase2 = None

while not (phrase1 == ""and phrase2 == ""):
    phrase1 = input("enter a number A  , or enter to quit > ")
    phrase2 = input("enter a number B  , or enter to quit > ")
    if (phrase1 == ""and phrase2 == ""):
        break
    else:
        A.append(int(phrase1))
        B.append(int(phrase2))
     

print(A,B)
for i in range(0,len(A)):
    if A[i] > B[i]:
        print("A需撤兵",A[i]-B[i])
    elif B[i] > A[i]:
        print("B需撤兵",B[i]-A[i])
    else:
        print("A,B 兵力相同")


========== == RESTART: F:/Python_APSC/a039.py ======================
輸入資料有多組,每一組有兩個正整數 A、B,代表 A、 B兩方的兵力。
當沒有資料可以輸入的時候,結束此程式。
enter a number A  , or enter to quit > 12
enter a number B  , or enter to quit > 34
enter a number A  , or enter to quit > 123
enter a number B  , or enter to quit > 125
enter a number A  , or enter to quit > 
enter a number B  , or enter to quit > 
[12, 123] [34, 125]
B需撤兵 22
B需撤兵 2
>>> 

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...