๐Ÿ“„ Python

3. if ์กฐ๊ฑด๋ฌธ

sa1t 2022. 6. 9. 10:36
๋ฐ˜์‘ํ˜•
# ์กฐ๊ฑด๋ฌธ IF
# if๋กœ ๋ช…๋ น์–ด๊ฐ€ ์‹คํ–‰๋  ์กฐ๊ฑด์„ ์ ๋Š”๋‹ค
# ์กฐ๊ฑด์ด ์ฐธ์ผ ๊ฒฝ์šฐ์— ๋‹ค์Œ์ค„์— ์‹คํ–‰ ํ•  ๋ช…๋ น์„ ์ž…๋ ฅํ•œ๋‹ค
# ๋“ค์—ฌ์“ฐ๊ธฐ ๋งž์ถ”๊ธฐ

a = 90
if a < 100 :
    print("์ฐธ ๊ฐ’ ์ž…๋‹ˆ๋‹ค. a๊ฐ€ 100๋ณด๋‹ค ์ž‘๋„ค์š”")
    print("์‹คํ–‰๋ฌธ์€ ์—ฌ๋Ÿฌ์ค„ ์‹คํ–‰ ๊ฐ€๋Šฅ")
else:
    print("๊ฑฐ์ง“ ๊ฐ’์ž…๋‹ˆ๋‹ค. a๊ฐ€ 100๋ณด๋‹ค ํฌ๋„ค์š”")
    print("์‹คํ–‰๋ฌธ์€ ์—ฌ๋Ÿฌ์ค„ ์‹คํ–‰ ๊ฐ€๋Šฅ")

print("if๋ฌธ ๋")

# ์กฐ๊ฑด๋ฌธ + ์‹คํ–‰๋ฌธ
# ์‹คํ–‰๋ฌธ์€ ์กฐ๊ฑด๋ฌธ์ด ์žˆ๋Š” ๋ธ”๋ก์—์„œ ํ•œ๋ฒˆ ๋“ค์—ฌ์“ฐ๊ธฐ ํ•ด์•ผํ•จ
# ํ•˜๋‚˜์˜ ์กฐ๊ฑด๋ฌธ์— ์—ฌ๋Ÿฌ์ค„์˜ ์‹คํ–‰๋ฌธ ์ž‘์„ฑ ๊ฐ€๋Šฅ
# ๋“ค์—ฌ์“ฐ๊ธฐ๋ฅผ ๋๋‚ด๋ฉด ์ž๋™์œผ๋กœ if๋ฌธ ์ข…๋ฃŒ ์ธ์‹


# Quiz)
# ์ˆซ์ž๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ์ง์ˆ˜์ธ์ง€ ํ™€์ˆ˜ ์ธ์ง€ ์ถœ๋ ฅ

num = int(input("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” : "))

if (num%2==0) :
    print("%d๋Š” ์ง์ˆ˜์ž…๋‹ˆ๋‹ค" %num)
else :
    print("%d๋Š” ํ™€์ˆ˜์ž…๋‹ˆ๋‹ค" %num)

# ํ•™์  ๊ณ„์‚ฐ๊ธฐ
# A ํ•™์  : 90 ~ 100
# B ํ•™์  : 80 ~ 89
# C ํ•™์  : 70 ~ 79
# D ํ•™์  : 60 ~ 69
# F ํ•™์  : 60์  ๋ฏธ๋งŒ

score = int(input("์ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š” : "))
if score >= 90:
    print("A")
else :
    if score >= 80:
        print("B")
    else :
        if score >=70:
            print("C")
        else:
            if score >=60:
                print("D")
            else:
                print("F")


score = int(input("์ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š” : "))
if score >= 90:
    print("A")
elif score >= 80 :
    print("B")
elif score >= 70:
    print("B")
elif score >= 60:
    print("B")
else :
    print("F")

# elif ๋ฌธ : ์กฐ๊ฑด์ด ์—ฌ๋Ÿฌ๊ฐœ์ผ ๋•Œ ์‚ฌ์šฉ

# Quiz)
# ์ˆซ์ž 3๊ฐœ ์ž…๋ ฅ ๋ฐ›์•„์„œ ํฐ ์ˆœ์„œ๋Œ€๋กœ ์ถœ๋ ฅ


num1=int(input("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))
num2=int(input("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))
num3=int(input("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))

if num1>num2 and num1>num3 and num2>num3:
    print(num1,num2,num3)
elif num1>num2 and num1>num3 and num3>num2:
    print(num1,num3,num2)
elif num2 > num1 and num2 > num3 and num1>num3:
    print(num2, num1, num3)
elif num2 > num1 and num2 > num3 and num3>num1:
    print(num2, num3, num1)
elif num3 > num1 and num3 > num2 and num1>num2:
    print(num3, num1, num2)
else :
    print(num3,num2,num1)



num1=int(input("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))
num2=int(input("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))
num3=int(input("์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))

if num1<num2:
    num1,num2 = num2,num1
if num2<num3:
    num2,num3=num3,num2
if num1<num2:
    num1,num2=num2,num1
print(num1,num2,num3)


# ์‚ฌ์น™์—ฐ์‚ฐ ๊ณ„์‚ฐ๊ธฐ
a,b,op = 0,0,0

a = int(input("์ฒซ๋ฒˆ์งธ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))
op = input("์—ฐ์‚ฐ์ž (+,-,*,/) : ")
b = int(input("๋‘๋ฒˆ์งธ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))

if op== "+" :
    print("%d + %d = %d " % (a,b,a+b))
elif op == "-":
    print("%d - %d = %d" %(a,b,a-b))
elif op == "*" :
    print("%d * %d = %d" %(a,b,a*b))
elif op == "/":
    print("%d / %d = %d" %(a,b,a/b))


# Quiz )
# ๊ณผ๋ชฉ 4๊ฐœ ์ ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ
# 4๊ณผ๋ชฉ ์ค‘ 1๊ฐœ๋ผ๋„ 40์  ๋ฏธ๋งŒ์ด๋ฉด "๊ณผ๋ฝ"
# 4๊ณผ๋ชฉ ํ‰๊ท  ์ ์ˆ˜๊ฐ€ 60์  ๋ฏธ๋งŒ์ด๋ฉด "ํƒˆ๋ฝ"
# 4๊ณผ๋ชฉ ํ‰๊ท  ์ ์ˆ˜๊ฐ€ 60์  ์ด์ƒ์ด๋ฉด "ํ•ฉ๊ฒฉ"

a=int(input("A ๊ณผ๋ชฉ์˜ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))
b=int(input("B ๊ณผ๋ชฉ์˜ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))
c=int(input("C ๊ณผ๋ชฉ์˜ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))
d=int(input("D ๊ณผ๋ชฉ์˜ ์ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : "))

if a<40 or b<40 or c<40 or d<40 :
    print("๊ณผ๋ฝ")
elif (a+b+c+d)/4 < 60:
    print("ํƒˆ๋ฝ")
elif (a+b+c+d)/4 >= 60:
    print("ํ•ฉ๊ฒฉ")




๊ณผ์ผ = ['์‚ฌ๊ณผ','๋ฐฐ','๋”ธ๊ธฐ','๊ณผ๋ฉ”๊ธฐ']
print(๊ณผ์ผ)
๊ณผ์ผ.append("๊ทค")
print(๊ณผ์ผ)


if '๋”ธ๊ธฐ' in ๊ณผ์ผ :
    print("๋”ธ๊ธฐ๋Š” ๊ณผ์ผ์ž…๋‹ˆ๋‹ค.")
๋ฐ˜์‘ํ˜•