PythonBasicHomework

1차 중간점검

출력

'python' 프로그래밍 언어입니다.
print(_______________________)

숫자형

 # 화씨 온도입니다. 섭씨 온도는 0도 입니다.
temperature1 = 32

# 섭씨 온도입니다. 화씨 온도는 89.6도 입니다.
temperature2 = 32

convert1 = @@@
convert2 = @@@

print('화씨 {}도는 섭씨 {}도'.format(temperature1, convert1)) # 화씨 32도는 섭씨 0도
print('섭씨 {}도는 화씨 {}도'.format(temperature2, convert2)) # 섭씨 32도는 화씨 89.6도

변수

# 변수명 = 값

문자열

print('Hello world!')
print("Hello world!")
print(''Hello world!'')
print(""Hello world!"")
print('''Hello world!''')
print("""Hello world!""")
a = 2023
b = 12
print(a + b)

a = "2023"
b = "12"
print(a + b)
s = 'Love yourself.'
print(s[0]) # L
print(@@@) # v
...
sentence = "Python에서 숫자 10과 문자 '10'은 다르다."

print(sentence[5])
print(sentence[-5])
print(sentence[10:12])
print(sentence[13:])
# s.format(____) 혹은 f'____' 사용
s = '공격받은 몬스터는 {}의 데미지를 받았습니다.'
print(@@@)
print(@@@)
print(@@@)
age = 12
age[0]

age = '12'
age[0]

입/출력

s = @@@
year = s[@@:@@]
month = s[@@:@@]
day = s[@@:@@]
weather = s[@@:@@]
print("{}년 {}월 {}일 / 날씨 : {}".@@@)

함수

# 함수 정의
_____ smile(s):
    end = ' :D'
    print(@@@)

# 함수 호출
smile('안녕하세요') # '안녕하세요 :D' 출력
smile('날씨가 좋아요') # '날씨가 좋아요 :D' 출력
# 함수 정의
_____ upset(s):
    end = ' :('
    return @@@

# 함수 호출
s1 = upset('넘어졌어요')
print(s1) # '넘어졌어요 :(' 출력
s2 = upset('오늘은 조금 피곤해요')
print(s2) # '오늘은 조금 피곤해요 :(' 출력
# 함수 정의
def @@@(won) :
    @@@
    return dollar

# 함수 호출
print('${}'.format(exchange(1300))) # $1
print('${}'.format(exchange(2600))) # $2
print('${}'.format(exchange(13000))) # $10
print('${}'.format(exchange(1000000))) # $769.23

won = int(input('환전할 원화 : '))
dollar = exchange(won)
print('당신은 ${} 를 환전했습니다.'.format(dollar))

bool 자료형

a = True
b = False
c = true
d = false
e = TRUE
f = FALSE

비교/논리 연산자

x = 4 
y = 9
print(x > y)
print(x < y)
print(x == y)
print(x != y)
print(x >= y)
print(x <= y)
print(x/10 < y)

print(10 == 10 and 10 != 5)
print(4 > 2 and 7 == 3)
print(10 < 5 or 10 > 3)
print(9 < 7 or 7 < 3)
print(not 10 >= 5)
print(not 10 <= 10)

조건문

print("1")
if True:
    print("2")
else :
    print("3")
print("4")
print("1")
if 3 > 7:
    if 10 == 9:
        print("2")
    else:
        print("3")
else :
    print("4")
print("5")
print("1")
if 'coding' == 'coding':
    if 'whale' == 'Whale':
        print("2")
    elif 3 != 3:
        print("3")
    else:
        print("4")
elif 3 == 3:
    print("5")
else :
    print("6")
print("7")
def even_odd(number):
    if @@@:
        print("짝수")
    else:
        print("홀수")

number = input("숫자 입력 : ")
even_odd(int(number))
num1 = input("input number1: ")
num2 = input("input number2: ")
num3 = input("input number3: ")
# 코드 작성
if @@@:
    print('{}이 가장 작은 숫자입니다.'.format(num1))
elif @@@:
    print('{}이 가장 작은 숫자입니다.'.format(num2))
elif @@@:
    print('{}이 가장 작은 숫자입니다.'.format(num3))
else:
    print(@@@) # 적절한 문자열을 출력하세요.
def print_price(transportation):
    adult_price = 0
    child_price = 0
    
    @@@
    
    print('{}의 성인 요금은 {}원, 어린이 요금은 {}원 입니다.'.format(transportation, adult_price, child_price))


transportation = input("사용할 교통편 : ")
print_price(transportation)

반복문

for i in range(@@@, @@@, @@@):
    if @@@:
        print(@@@)
        

i = 0
while @@@:
    i = i + 1
    if @@@:
        print(@@@)
while True:
    capital = input('한국의 수도는? : ')
    
    if capital == '그만' : 
        @@@
    elif @@@:
    ...

# 80~100 : A등급
# 60~79 : B등급
# 40~59 : C등급
# 20~39 : D등급
# 0~19 : E등급
# 100 초과, 0 미만 : 잘못된 입력

while True:
    score = input("점수: ")
    
    @@@
age = int(input('나이 : ')) # 사용

자료형

a = 1000
b = '1000'
c = True
d = 'False'
e = 'hello world!'
f = TRUE
g = 30.1
h = '2023'
i = true
j = 'false'
k = -59
l = 0
m = '0'
n = '2023'+'11'
o = False
p = 1000 + 100 - 99
q = '*' * 10
r = 10 * 10
s = '100' <= 10
t = 100 > 10
u = false

반복문2

number = input('숫자 입력 : )
@@@

# 3 입력
***
***
***

# 5 입력
*****
*****
*****
*****
*****
number = input('숫자 입력 : )
@@@

# 3 입력
*
**
***

# 5 입력
*
**
***
****
*****
number = input('숫자 입력 : )
@@@

# 3 입력
  *
 **
***

# 5 입력
    *
   **
  ***
 ****
*****
number = input('숫자 입력 : )
@@@

# 3 입력
  *
 ***
*****

# 5 입력
    *
   ***
  *****
 *******
*********
# 함수 정의
def operations(@@@, @@@):
    r1 = num1 + num2
    r2 = @@@
    r3 = @@@
    r4 = @@@
    print('{} + {} = {}'.format(@@@, @@@, @@@))
    print('{} - {} = {}'.format(@@@, @@@, @@@))
    print('{} * {} = {}'.format(@@@, @@@, @@@))
    print('{} / {} = {}'.format(@@@, @@@, @@@))
    return @@@

# 함수 호출
num1 = @@@
num2 = @@@
result = operations(@@@, @@@)
print(result)