[파이썬 문제풀이 스터디] 1주차

23521 단어 파이썬파이썬

STEP 1. 출력문 print()

Problem 006

# (1)
print(14590)

# (2)
# print(abc) # error

# (3)
print(13-2)

# (4)
print(12 + 4 / 2 + 1)

# (5)
print("A" + "B" + " C")

# (6)
# print("A" - "B") # error

# (7)
print("A" + 'B')

# (8)
# print(52 - "33") # error

Problem 008

# 1
print("23"+"Bc"+"7")

# 2
print(23, end='')
print("Bc7")

Problem 009

print('a')
print('b', 'c', end='')
print('D')
print('E', end='F')

# a
# b cD
# EF

STEP 2. 변수 variable

Problem 016

x, y, z = 1, 2, 3
print((2*(y+z))**x)
print((2*(y+z))**y)
print((2*(y+z))**z)

Problem 020

num1, num2, num3 = 10, 20, 30
num1 = num2 = num3

print(num1)
print(num2)
print(num3)

Problem 021

X, Y, Z = 1, 2, 1.5

print(X)          # 1
print(X + Y)      # 3
print(X + Y + Z)  # 4.5
# print(2X)
print(2 * X)      # 2
print(2.0 * X)    # 2.0
print(X - 1.0)    # 0.0
print(X - 1)      # 0
print(Z - 0.5)    # 1.0
# print(XZ)
print(X * Z)      # 1.5

STEP 3. 포맷 format

Problem 023

country = "Korea"
population = '50M'
print("{} has about {} people".format(country, population))

Problem 024

num1 = 1.23456789
num2 = 0.22222222
num3 = 1.87654321
num4 = 0.21314151

print("First : {:2}".format(num1))           # 1.23 --> 틀림
print("Second : {:10.4}".format(num2))       #     0.2222
print("Third : {}".format(num3))             # 1.87654321
print("Fourth : {:10.4}".format(num4))       #     0.2131

STEP 4. 연산자

Problem 032

A, B, C = 1, 2, 3

A += A * B + A        # A * B + A = 3, A = 4
B %= A % C % B        # 4 % 3 % 2 = 1, B = 0
C *= C - A ** (A -3)  # 3 - 4**(1) = -1, C = -3

print(A)
print(B)
print(C)

Problem 033

X, Y, Z, W = 11, 5, 7, 13

print(X % Y)
print((Z % Y) * Y)
print(((Z % Y) * Y) ** (Z % Y))
print(((Z % Y) * Y) ** (W % Y))

Problem 036

print("1의 자료형은", end=' ')
print(type(1))
print("1.0의 자료형은", end=' ')
print(type(1.0))

STEP 5. 비트연산

Problem 042

a, b, c = 11, 22, 33

print(bin(a))
print(hex(22))
print(oct(c))
print(bin(c*2))

Problem 045

num1 = 3
num2 = 6
num3 = 2

print(num1 & num2)     # 2
print(num1 | num2)     # 7
print(num1 ^ num2)     # 5
print(num1 & num2 & num3)  # 2

Problem 047

num = 7
num = num << 1
print(num)

STEP 6. boolean

Problem 057

print(((8 == 14) | (165 < 178) & (1 == 17)) ^ (814 > 117))

Problem 058

num = 17
print(num == 0)

Problem 059

num1 = 6
num2 = 7

print(num1 % 2 == 0 or num1 % 3 == 0)
print(num2 % 2 == 0 or num2 % 3 == 0)

좋은 웹페이지 즐겨찾기