ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [payment. py] Python으로 만든 더치페이 프로그램
    Python 2020. 9. 7. 13:38

    프로그램이라고 하기엔 너무 간단하지만

    만들어보았다.

    import time
    pay = []
    i = 0;
    j = 0
    t = 0
    with open("payment.md") as md:
    	for line in md.readlines():
    		pay.append(line.split())
    		if (pay[i][0] == "j"):
    			pay[i][0] = "myself"
    			j += int(pay[i][2])/int(pay[i][3])
    		else:
    			pay[i][0] = "friend"
    			t += int(pay[i][2])/int(pay[i][3])
    		menu_len = len(pay[i][1])
    		blank = 10 - menu_len
    		half_blank = int(blank / 2)
    		pay[i][1] = "|" + (" " * half_blank) + pay[i][1] + (" " * int(blank - half_blank)) + "|"
    		i += 1
    
    num = 0
    title = "Payment"
    print("\n{:=^50}\n".format(title))
    print(" {:^7}|{:^16}|{:^12}".format("😎", " 🍙🍔🍜🦴 ", " 💸 / 🧍 or 🧍🧍"))
    print("------------------------------------------------")
    for num in range(i):
    	print("{:^9}{}  {}".format(pay[num][0], pay[num][1], pay[num][2]+"/"+pay[num][3]))
    	num += 1
    title = "Result⚖️ "
    print("\n{:=^50}\n".format(title))
    print("	{}".format("myself : 총" + str(int(j)) + "원 냈습니다."))
    print("	{}".format("friend : 총" + str(int(t)) + "원 냈습니다."))
    print("	{}".format("Reseult is ...❇️💰"))
    time.sleep(1)
    print("	+-------------------------+")
    print("	|                         |")
    if j == t:
    	print("	|          쌤쌤!          |")
    	print("	|     myself과 friend이   |")
    	print("	|   같은 금액을 썼습니다. |")
    if j > t:
    	print("	|        myself Win!      |")
    	print("	|   friend이 myself에게   |")
    	print("	|{:^6}{:^12}|".format(int(j - t), "(원)을 지불하세요"))
    if t > j:
    	print("	|       friend Win!       |")
    	print("	|   myself이 friend에게   |")
    	print("	|{:^5}{:^13}|".format(int(t - j), "(원)을 지불하세요"))
    print("	|                         |")
    print("	+-------------------------+")
    print("\n{:=^50}\n".format(""))

     

     

    결과 보기

    더보기

    누가 누구한테 얼마를 줘야하는지 나온다.

    =====================Payment======================
    
        😎   |      🍙🍔🍜🦴      | 💸 / 🧍 or 🧍🧍
    ------------------------------------------------
     myself  |   옥동식    |  19000/2
     myself  |  합정리과일집  |  22400/2
     myself  |   맥도날드   |  7500/1
     friend  |   운남덮밥   |  26500/2
     friend  | 소크라테스떡볶이 |  26100/2
    
    ====================Result⚖️ =====================
    
    	myself : 총28200원 냈습니다.
    	friend : 총26300원 냈습니다.
    	Reseult is ...❇️💰
    	+-------------------------+
    	|                         |
    	|        myself Win!      |
    	|    friend이 myself에게    |
    	|   1900  (원)을 지불하세요   |
    	|                         |
    	+-------------------------+
    
    ==================================================

    댓글

Designed by Tistory + Edited by Juepark