수학시간 파이썬
-
파이썬으로 로또 번호 랜덤 생성기 만들기수학시간 파이썬 2024. 9. 13. 18:08
#방법 1 ✓ 사용한 기능더보기닫기import randomsorted(lotto)random.sample✓ 코드import randomnumbers = range(1,46) #1~45까지의 수를 생성lotto = random.sample(numbers,6) #6개의 랜덤한 수 생성, 변수에 저장sorted_lotto = sorted(lotto) #lotto를 오름차순 정렬 수 변수에 저장print(sorted_lotto) #출력>>>[11, 18, 23, 36, 38, 44] #방법2 토요일에 1등이 될 나의 모습을 상상하며 잠들기...전에 잊지 말고 로또 사기 (제일 중요...!)
-
파이썬으로 직각삼각형의 빗변의 길이 구하는 프로그램 만들기수학시간 파이썬 2024. 3. 6. 21:26
#사용한 기능 더보기 식별자 print() int() * 연산자 #피타고라스의 정리 직각삼각형의 빗변의 길이가 c, 다른 두 변의 길이가 각각 a, b일 때 피타고라스의 정리에 따라 빗변의 길이를 구하는 프로그램 빗변의 길이의 c, 다른 두 변의 길이를 a, b라 할 때, !c = \sqrt[]{}(a^{2}+b^{2})* 더보기 정답 #입력 a = input("밑변: ") b = input("높이: ") a = float(a) b = float(b) #처리 c = ((a**2)+(b**2))**(1/2) #출력 print (f"밑변의 길이 : {a}") print (f"높이의 길이 : {b}") print (f"빗변의 길이는 {c}입니다.")
-
파이썬으로 구의 겉넓이, 부피 구하는 식 만들기수학시간 파이썬 2024. 3. 6. 21:23
#사용한 기능 더보기 식별자 print() int() * 연산자 # 구의 부피와 겉넓이를 구하는 프로그램 (단, 원주율은 3.14로 계산한다.) 구의 반지름을 r이라고 할 때 부피 : ! \frac{4}{3}\pi r^{3} * 겉넓이 : ! 4\pi r^{2} * 더보기 정답 pi = 3.14 r = input("구의 반지름을 입력해주세요: ") print("구의 부피는 {}입니다.".format((4/3)*pi*float(r)**3)) print("구의 겉넓이는 {}입니다.".format(4*pi*float(r)**2)) 다른 정답 #입력 rad = input("구의 반지름을 입력해주세요: ") rad = float(rad) #처리 부피 = (4/3)*pi*(rad**3) 겉넓이 = 4*pi*(rad..
-
파이썬으로 삼각형, 사다리꼴의 넓이 구하는 식 만들기수학시간 파이썬 2024. 3. 6. 21:14
#사용한 기능 더보기 식별자 print() int() * 연산자 # 삼각형 # 밑변의 길이가 b, 높이가 h인 삼각형의 넓이를 s라 할 때, print("삼각형의 넓이") #입력 b = input("밑변의 길이: ") h = input("높이: ") #처리 b = int(b) h = int(h) #출력 s = b*h*(1/2) print(s) #사다리꼴 # 윗변의 길이가 x, 아랫변의 길이가 y, 높이가 hi인 사다리꼴 넓이를 tr이라 할 때, print("사다리꼴의 넓이") #입력 x = input("윗변의 길이: ") y = input("아랫변의 길이: ") hi = input("높이 : ") #처리 tr = (1/2)*(int(x)+int(y))*int(hi) #출력 print(tr)