320x100
# 8일차 - 함수의 매개변수와 카이사르 암호
# 입력 값이 있는 함수
# Review:
# Create a function called greet().
# Write 3 print statements inside the function.
# Call the greet() function and run your code.
def greet():
print("a")
print("b")
print("c")
greet()
# Function that allows for input
def greet_with_name(name):
print("Hello %s" % name)
print("How do you do %s" % name)
print(f"nice to meet you{name}")
print(f"give me money {name}")
greet_with_name("조강조")
# 여기서 정의 되는 함수 def ~~~() 에서 ()안에는 초기값이 들어간다.
#### 중요~!!! 위에서 처음 def~~~(name)에 들어가는 name 을 parameter 라고 부르고
# 맨 밑에 "조강조"라고 정의함수를 출력하는 초기값의 입력값을 argument 라고 부른다.
# 80. 위치 인자와 키워드 인자.
#Simple Function
# def greet():
# print("Hello Angela")
# print("How do you do Jack Bauer?")
# print("Isn't the weather nice today?")
# greet()
# #Function that allows for input
# #'name' is the parameter.
# #'Jack Bauer' is the argument.
# def greet_with_name(name):
# print(f"Hello {name}")
# print(f"How do you do {name}?")
# greet_with_name("Jack Bauer")
# #Functions with more than 1 input
# def greet_with(name, location):
# print(f"Hello {name}")
# print(f"What is it like in {location}?")
# #Calling greet_with() with Positional Arguments
# greet_with("Jack Bauer", "Nowhere")
# #vs.
# greet_with("Nowhere", "Jack Bauer")
# #Calling greet_with() with Keyword Arguments
# greet_with(location="London", name="Angela")
# Function with more than 1 input
def greet_with(name, location):
print("Hello %s"%name)
print("what is like in %s"%location)
greet_with("EverLand","Naver")
# 파라미터값은 초기값으로써 자리변화가 없다.
# 하지만 입력 방법에 따라서, 입력하는 환경, 사람등에 의해서 아규먼트는 변할 수있다.
# 이 변동을 막기 위해서 고안된것이
# greet_with(name="Naver",location="Everland")
# 이런식으로 묶어주는 것이다.
# 81.인터랙티브 코딩 연습 페인트 면적 계산기
#Write your code below this line 👇
#Write your code above this line 👆
# Define a function called paint_calc() so that the code below works.
import math
def paint_calc(height,width,cover):
# 내가쓴 코드 틀렸다. 하기사 답이 6850인가? 로 나오는데 페인트통이 185에 185만큼 칠하는데 그만큼 필요할리가없지
#paint_unit = (height*width)/cover
#print(paint_unit)
# number of cans = (wall height * wall width) / coverage per can
# 해설코드
area = height * width # 이거는 총면적 구해주는것 m2로
num_of_cans = math.ceil(area /cover) # 하지만 math.ceil은 무조건 소수 뒷자리를 올려주는것이기 때문에
#round가 내 기억으론 반올림이였던 것으로 기억나므로 뭔가 상황에 따라서
# 맞는것을 쓰는게 맞다고 본다.
# 만약 페인트를 실제로 사와야하는 상황이라면 math.ceil처럼 무조건
# 올림해야지. 왜냐면 페인트 모자란 부분을 못칠하면 안되잖아.
print(f"You'll need {num_of_cans} cans of paint")
# 🚨 Don't change the code below 👇
test_h = int(input("Height of wall: "))
test_w = int(input("Width of wall: "))
coverage = 5
paint_calc(height=test_h, width=test_w, cover=coverage)
300x250
'개발일지 > 임시카테고리' 카테고리의 다른 글
2022.02.11 파이썬정복 16장 모듈과 패키지 (0) | 2022.02.11 |
---|---|
2022.02.11 열왕기상 14장 똥과 설사의 싸움 (0) | 2022.02.11 |
2022.02.10 15.2강 여러가지 메서드 (나중에 중요 array) (0) | 2022.02.10 |
2022.02.10 요한복음 13장. 답습과 사랑에 대한 고찰 (0) | 2022.02.10 |
2022.02.09 파이썬정복 15장-1 클래스 (0) | 2022.02.09 |