i = 100 # 특정값

while i % 27 != 0: #i를 27로 나눴을 때 나머지가 0이 될 때까지 = 27의 배수일 때까지

i = i + 1

print(i)


#특정 값을 초과하는 배수기 때문에 처음부터 while 반복 문 안에 i = 특정값을 설정해주고, n의 배수표현을 i % n 으로 해주는 것

i = 1

while i <= 50:

print(i * 2)

i = i + 1


def even_or_odd(number):

return number & 2 == 0


print(even_or_odd(3)) #결과값 False

print(even_or_odd(4)) #결과값 true

#돈을 냈을 때, 5만원, 1만원, 5천원, 1천원의 지폐의 합이 최소가 되도록 거스름돈을 알려주는 예제

#payment=내가 내는 돈, cost=상품의 가격


#함수 정의

def calculate_change(payment, cost):

change = payment - cost

fifty_thousand = int(change / 50000)


change = change % 50000

ten_thousand = int(change / 10000)


change = change % 10000

five_thousand = int(change / 5000)


change = change % 5000

one_thousand = int(change / 1000)


print("거스름돈은 다음과 같습니다")

print() #공백

print("50000원짜리 지폐 : " + str(fifty_thousand) + "장")

print("10000원짜리 지폐 : " + str(ten_thousand) + "장")

print("5000원짜리 지폐 : " + str(five_thousand) + "장")

print("1000원짜리 지폐 : " + str(one_thousand )+ "장")


#100,000원을 내고 54,000원짜리 상품을 구매할 때 받는 거스름돈

calculate_change(100000, 54000)


#다른 방법으로 함수 정의하기

def calculate_change(payment, cost):

change_money = payment - cost
fifty_thousands = change_money//50000
ten_thousands = (change_money - fifty_thousands*50000)//10000
five_thousands = (change_money - fifty_thousands*50000 - ten_thousands*10000)//5000
thousands = (change_money - fifty_thousands*50000 - ten_thousands*10000 - five_thousands*5000)//1000

print("50000원 지폐: " + str(fifty_thousands) + "장")
print("10000원 지폐: " + str(ten_thousands) + "장")
print("5000원 지폐: " + str(five_thousands) + "장")
print("1000원 지폐: " + str(thousands) + "장")






+ Recent posts