Light theme icon (depiction of a sun)
Dark theme icon (depiction of a moon)
โ€˜๐ŸŽฏ ํ† ์ด ํ”„๋กœ์ ํŠธโ€™ ์‹œ๋ฆฌ์ฆˆ

๐ŸŽฒ ์ฃผ์‚ฌ์œ„ ํ”„๋กœ๊ทธ๋žจ

  • 0
  • 3
0
3

๋ฌธ์ œ

๋กœ์ง

  1. ์ปดํ“จํ„ฐ์™€ ๋‚ด๊ฐ€ ์ฃผ์‚ฌ์œ„ 2๊ฐœ๋ฅผ ๊ตด๋ฆฐ๋‹ค.
    • ์ฃผ์‚ฌ์œ„๋Š” ๋žœ๋ค๊ฐ’์œผ๋กœ ์ฒ˜๋ฆฌํ•ด์•ผํ•œ๋‹ค. (์ฃผ์‚ฌ์œ„ ๊ฐ’์„ ์•ˆ๋‹ค๋ฉด ๊ทธ๊ฑด ์ฃผ์‚ฌ์œ„๊ฐ€ ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์—)
    • ์ปดํ“จํ„ฐ ์ฃผ์‚ฌ์œ„ 2๊ฐœ, ๋‚ด ์ฃผ์‚ฌ์œ„ 2๊ฐœ๋ฅผ ๋žœ๋ค๊ฐ’์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•ด์•ผํ•œ๋‹ค.
  2. ์ฃผ์‚ฌ์œ„ ๋ˆˆ๊ธˆ์˜ ํ•ฉ์ด ํฐ ์ชฝ์ด ์ด๊ธด๋‹ค.
    • ์ปดํ“จํ„ฐ ์ฃผ์‚ฌ์œ„์™€ ๋‚ด ์ฃผ์‚ฌ์œ„์˜ ๊ฐ’์„ ๊ฐ๊ฐ ๋”ํ•˜๋Š” ๋ณ€์ˆ˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
    • if๋ฌธ์œผ๋กœ ์ปดํ“จํ„ฐ๊ฐ€ ์ด๊ฒผ๋Š”์ง€ ๋‚ด๊ฐ€ ์ด๊ฒผ๋Š”์ง€ ์กฐ๊ฑด์ฒ˜๋ฆฌ ํ•ด์ฃผ๋ฉด ๋จ
  3. ๋‘ ๋ˆˆ๊ธˆ์ด ๊ฐ™์œผ๋ฉด ํ•ฉ์— 10์„ ๋”ํ•œ๋‹ค.
    • ๋น„๊ธฐ๋ฉด ๋ˆˆ๊ธˆ์˜ ํ•ฉ์— 10์„ ๋”ํ•œ๋‹ค.
    • ์ด๊ฒƒ๋„ if๋ฌธ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋ฉด ๋จ
  4. ์œ„ ๊ณผ์ •์„ 5๋ฒˆ ๋ฐ˜๋ณตํ•˜์—ฌ ๋‚ด๊ฐ€ ๋ช‡ ์Šน ๋ช‡ ๋ฌด ๋ช‡ ํŒจ์ธ์ง€ ํ™”๋ฉด์— ์ถœ๋ ฅ
    • 5๋ฒˆ ๋ฐ˜๋ณต์€ for๋ฌธ์ด๋‚˜ while๋ฌธ์„ ์‚ฌ์šฉํ•œ๋‹ค.
    • ๋ช‡ ์Šน ๋ช‡ ๋ฌด ๋ช‡ ํŒจ๋Š” for๋ฌธ ๋ฐ–์— ์„ ์–ธํ•ด์„œ ์ „์—ญ์ ์œผ๋กœ ๊ด€๋ฆฌํ•œ๋‹ค.
    • for๋ฌธ ์•ˆ์— ์„ ์–ธํ•˜๋ฉด ์ง€์—ญ์ ์œผ๋กœ ์„ ์–ธ๋˜์„œ for๋ฌธ์ด ๋๋‚˜๋ฉด ์‚ฌ๋ผ์ง„๋‹ค.

์ฝ”๋“œ

import random

if __name__ == '__main__':
    win = 0
    lose = 0
    draw = 0

    for i in range(5):
        com_dice_1 = random.randrange(1,7)
        com_dice_2 = random.randrange(1,7)
        my_dice_1 = random.randrange(1,7)
        my_dice_2 = random.randrange(1,7)

        sum_com_dice = com_dice_1 + com_dice_2
        sum_my_dice = my_dice_1 + my_dice_2

        if sum_com_dice > sum_my_dice:
            lose = lose + 1
            print("(" + str(com_dice_1) + ", " + str(com_dice_2) + ")")
            print("\n")
        elif sum_com_dice < sum_my_dice:
            win = win + 1
            print("(" + str(my_dice_1) + ", " + str(my_dice_2) + ")")
            print("\n")
        elif sum_com_dice == sum_my_dice:
            print("(" + str(my_dice_1) + ", " + str(my_dice_2) + ")")
            print(sum_my_dice + 10)
            draw = draw + 1
            print("\n")

    print(str(win) + " ์Šน, " + str(draw) + " ๋ฌด, " + str(lose) + " ํŒจ")

๊ฒฐ๊ณผ

์ฒซ ๋ฒˆ์งธ ์ถœ๋ ฅ์€ ๋งŒ๋“ค์ž๋งˆ์ž ์บก์ณํ•œ๊ฑฐ๊ณ , ๋‘ ๋ฒˆ์งธ ์ถœ๋ ฅ์€ ๋งŒ๋“ค๊ณ  ์ข€ ๋‹ค๋“ฌ์–ด์„œ ์ถœ๋ ฅํ•œ ๊ฒƒ. ์—ฌ๋Ÿฌ๋ฒˆ ๋ฐ˜๋ณตํ•˜๋ฉด์„œ ์ฃผ์‚ฌ์œ„์˜ ๋ฒ”์œ„๋Š” ๋งž๋Š”์ง€, ๋น„๊ฒผ์„ ๋•Œ , ๋‚ด๊ฐ€ ์ด๊ฒผ์„ ๋•Œ, ์ปดํ“จํ„ฐ๊ฐ€ ์ด๊ฒผ์„ ๋•Œ ์ž˜ ๋™์ž‘ํ•˜๋Š”์ง€ ํŒŒ์•…ํ•ด์•ผ ํ•œ๋‹ค.

0๋ถ„์ „
์ž‘์„ฑ๋œ ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค. ์ฒซ ๋Œ“๊ธ€์„ ๋‹ฌ์•„๋ณด์„ธ์š”!
    ๋Œ“๊ธ€์„ ์ž‘์„ฑํ•˜๋ ค๋ฉด ๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.