์ƒˆ์†Œ์‹

Languages/Python

[Python] ๊ตฌ๊ตฌ๋‹จ, ํ™€์ˆ˜์ง์ˆ˜ ํ”„๋กœ๊ทธ๋žจ

  • -
๋ฐ˜์‘ํ˜•

ํŒŒ์ด์ฌ์€ ์ฐธ ์‰ฝ๋„ค์š”..

 

์ž…๋ ฅ๋ฐ›๊ณ  -> ๋ฐ›์€ ๊ฐ’์˜ ํ•ด๋‹นํ•˜๋Š” ๋‹จ๋งŒ ์ถœ๋ ฅ ์‹œํ‚ค๋Š” ํ”„๋กœ๊ทธ๋žจ์ž…๋‹ˆ๋‹ค.

 

print("######### ๊ตฌ๊ตฌ๋‹จ ์ถœ๋ ฅ ํ”„๋กœ๊ทธ๋žจ #########")
num = 0 #์ž…๋ ฅ ๋ฐ›๋Š” ๋‹จ์˜ ๊ฐ’
while 1:# ํ•ญ์ƒ true ๋ฌดํ•œ ๋ฐ˜๋ณต
    num = int(input("\n๋‹จ ์ž…๋ ฅ : "))
    if num == 0:
        print(">> 0๋‹จ์€ ์‹คํ–‰ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
        break

    for i in range(num, num+1):
        for j in range(1, 10):
            print(i, "*", j, "= %d" % (i * j))

 

๊ฒฐ๊ณผ:

 

๋‹ค์Œ์€  ์ž…๋ ฅ ๊ฐ’๋“ค ์ค‘ ํ™€์ˆ˜์™€ ์ง์ˆ˜๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ณ  ํ™€์ˆ˜ํ•ฉ, ์ง์ˆ˜ํ•ฉ, ์ดํ•ฉ์„

๊ตฌํ•ด์ฃผ๋Š” ํ”„๋กœ๊ทธ๋žจ์ž…๋‹ˆ๋‹ค.

 

print("์ง์ˆ˜ ํ™€์ˆ˜ ํŒ๋ณ„ ํ”„๋กœ๊ทธ๋žจ")
num_list = []

for i in range(1,11): #1~10๊นŒ์ง€ (10๋ฒˆ ๋Œ๋ฉด์„œ 10๊ฐœ์˜ ์ˆ˜๋ฅผ ์ €์žฅ)
    num = int(input("%d๋ฒˆ์งธ ์ž„์˜์˜ ์ˆ˜ ์ž…๋ ฅ >>>" %i))
    num_list.append(num)
    i = i+1
print("๋ฆฌ์ŠคํŠธ ๋‚ด์šฉ : ",num_list)

# ์ง์ˆ˜ ํ™€์ˆ˜ ๊ตฌํ•˜๊ธฐ
i = 0
sum1 = 0
sum2 = 0
for i in num_list:
    if (i % 2) == 0:
#        print("์ง : ",i)
        sum1 += i
    else:
#        print("ํ™€ : ", i)
        sum2 += i
    i = i+1


print("์ง์ˆ˜์˜ ํ•ฉ : ", sum1)
print("ํ™€์ˆ˜์˜ ํ•ฉ : ", sum2)
print("์ด ํ•ฉ : ", sum1+sum2)

 

๊ฒฐ๊ณผ:

 

์†”์งํžˆ ์—ฐ์Šต์šฉ ์ฝ”๋“œ์˜€๊ธฐ ๋•Œ๋ฌธ์—, ์‚ฌ์šฉ๋ฒ•์„ ์ตํžˆ๋Š” ๊ฒƒ์— ์ค‘์ ์„ ๋‘์–ด ๊ฐ€๋…์„ฑ์ด ์กฐ๊ธˆ ๋–จ์–ด์ง€๋Š” ์ ..

์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค ใ… _ใ… 

๋ฐ˜์‘ํ˜•
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.