Python Tutorial: Find Square Root and Area of Triangle | Problem Solving In Python

preview_player
Показать описание
In this Python tutorial, we demonstrate how to calculate the square root of a number and the area of a triangle using simple programs. This beginner-friendly project is perfect for those new to programming and looking to build their Python skills. By the end of this video, you'll have learned how to use the `math` module for mathematical calculations and how to apply formulas to solve real-world problems. Don't forget to like, share, and subscribe for more Python tutorials and projects!

**Steps of the Algorithm:**

**Square Root Calculation:**
1. **Import Math Module**: Import the `math` module to access mathematical functions.
2. **Prompt User for Number**: Use the `input()` function to prompt the user to enter a number.
3. **Convert Input to Float**: Convert the input string to a float using the `float()` function.
5. **Print the Square Root**: Use the `print()` function to display the calculated square root.

**Area of Triangle Calculation:**
1. **Prompt User for Base and Height**: Use the `input()` function to prompt the user to enter the base and height of the triangle.
2. **Convert Inputs to Float**: Convert the input strings to floats using the `float()` function.
3. **Calculate Area**: Use the formula `area = 0.5 * base * height` to calculate the area of the triangle.
4. **Print the Area**: Use the `print()` function to display the calculated area.

**Detailed Steps:**

**Square Root Calculation:**
1. **Import Math Module**:
- Use `import math` to import the `math` module, which provides the `sqrt()` function.
2. **Prompt User for Number**:
- Use the `input()` function to ask the user for a number.
3. **Convert Input to Float**:
- Use the `float()` function to convert the number from a string to a floating-point number.
4. **Calculate Square Root**:
5. **Print the Square Root**:
- Use the `print()` function to display the square root.

**Area of Triangle Calculation:**
1. **Prompt User for Base and Height**:
- Use the `input()` function to ask the user for the base and height of the triangle.
2. **Convert Inputs to Float**:
- Use the `float()` function to convert the base and height from strings to floating-point numbers.
3. **Calculate Area**:
- Use the formula `area = 0.5 * base * height` to calculate the area of the triangle.
4. **Print the Area**:
- Use the `print()` function to display the area of the triangle.
Рекомендации по теме
Комментарии
Автор

I’ve gathered many years of scientific research and read hundreds of studies and
all of the data shows that subscribing to Youth Nation Coders will allow you to live
longer. Sorry, data never lies..Click Below:

PythonGuruji
Автор

# Copyright 2020.11.04. 신촌우왕TV수학자.천재작곡가 All rights reserved.
# Python Code: 임의의 실수(Real Number)에 대한 SQUARE ROOT 값을 구하기
# 루트 207.109의 소수점 50자리까지의 값은?
# sqrt("207.109", 50) =
# sNUM: 문자열 형식의 입력 숫자 (예: sNUM = '207.109')
# nDIGIT: 계산결과에서 원하는 소수점 이하의 자리수 (예: nDIGIT = 50)
def sqrt_by_WooKing(sNUM, nDIGIT):
u = ''

v = sNUM.split('.')

# sNUM에 '.'이 없으면
if len(v)==1:
u = v[0] + '.' + '0'*(nDIGIT*2)
elif len(v)==2:
if len(v[1])<nDIGIT*2:
u = v[0] + '.' + v[1] + '0'*( nDIGIT*2 - len(v[1]) )

# sNUM: '23.0170'
# w[0]: interger part ('23')
# w[1]: decimal part ('0170')
w = u.split('.')

N = int(w[0])

s = [0, N, '']

for i in range(nDIGIT+1):
for a in range(10 + N):
u = ((s[0])*10 + a)*a
v = ((s[0])*10 + a+1)*(a+1)

if u <= s[1] and s[1] < v:
s[2] += str(a)

s[0] = ((s[0])*10 + a) + a

idx = i*2
s[1] = int ( str(s[1] - u) + (w[1][idx:(idx+2)]) )

break

if i==0:
s[2] += '.'

# 계산 결과가 s[2]에 들어있음.
return s[2]

if __name__=='__main__':
sNUM = '207.109'
nDIGIT = 50
my_sqrt = sqrt_by_WooKing(sNUM, nDIGIT)

#
# 루트 207.109의 소수점 50자리까지의 값:
#
# <- Microsoft Windows' Calculator

tv..
Автор

# Copyright 2020. 신촌우왕TV수학자.천재작곡가 All rights reserved.
# 루트 2 =
# Python Code: 임의의 자연수에 대한 ROOT 값을 구하기
ROOT = 2 # ROOT 2의 값. 3으로 변경하면 ROOT 3의 값이 구해짐.
DIGIT = 50 # 소수점 아래 50자리까지 구하기

s = [0, ROOT, ""]

for i in range(DIGIT+1):
for a in range(10 + ROOT):
u = ((s[0])*10 + a)*a
v = ((s[0])*10 + a+1)*(a+1)

if u <= s[1] and s[1] < v:
s[2] += str(a)

s[0] = ((s[0])*10 + a) + a
s[1] = (s[1] - u) * 100

break

if i==0:
s[2] += "."

# 계산 결과가 s[2]에 들어있음.
print("루트 %d의 소수점 %d자리까지의 값:\n%s"%(ROOT, DIGIT, s[2]))
#print("Length: ", len(s[2]))
##
# 루트 2의 소수점 50자리까지의 값:
#

tv..
visit shbcf.ru