Bài 1
Xác định bài toán:
Imput nhập tọa độ x1, y1 của điểm A và tọa độ x2, y2 của điểm B
Output: độ dài đoạn thẳng AB
Thuật toán:
Áp dụng công thức:
dAB=((x2-x1)^2+(y2-y1)^2)
Code:
from math import sqrt
x1=int(input())
y1=int(input())
x2=int(input())
y2=int(input())
dAB= sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
print("{:.3}".format(dAB))
Bài 2
Xác định bài toán:
Imput: nhập giá trị a, b, c là ba cạnh của tam giác AB
Output: chu vi và diện tích tam giác ABC
Thuật toán:
Áp dụng công thức:
p=(a+b+c)/2
s=căn(p*(p-a)*(p-b)*(p-c))
Code:
from math import sqrt
a=int(input())
b=int(input())
c=int(input())
p = (a+b+c)/2
s = sqrt( (a+b+c)/2)*( (a+b+c)/2)-a)*( (a+b+c)/2)-b)*( (a+b+c)/2)-c))
print("{:.10}".format(s))
Bài 3:
Xác định bài toán:
Input: nhập tọa độ x1,y1 của điểm A, x2,y2 của điểm B và x3,y3 của điểm C là ba đình của tam giác ABC
Output: độ dài các đoạn thẳng dAB, dBC, dCA
Thuật toán:
Áp dụng công thức:
dAB=căn((x2-x1)^2+(y2-y1)^2)
Cođe:
from math import sqrt
x1 = int(input())
x2 = int(input())
x3 = int(input())
y1 = int(input())
y2 = int(input())
y3 = int(input())
dab= sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
dbc=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2)
dca= sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3))
print(" {:.3f}".format(dab))
print("{:.3f}".format(dbc))
print("{:.3f}".format(dca))
Bài 1_10_10_2022
Code:
from math import sqrt
m=int(input())
n=int(input())
x=int(input())
y=int(input())
q=(m**m+n)*(x+y)
p=(x**3+y**4)/(m+n)
print(q)
print(p)
4
5
6
7
kq:
3393
290.77777777777777
Bài 4
Xác định bài toán:
Imput: nhập giá trị a, b là kích thước của hinh chữ nhật,
Output: số gạch vàng và số gạch xanh
Thuật toán:
Áp dụng công thức:
Gợi y là số viên gạch màu vàng x=(a-2)*(b-2)
Gọi x là số viên gạch màu xanh y=a*b- x
Code:
a = int(input("Nhap a: "))
b = int(input("Nhap b: "))
x = (a-2) * (b-2)
y = a * b - x
print(x)
print(y)
Bài 5
Xác định bài toán:
Imput: nhập giá trị của n
Output: giá trị của s
Thuật toán:
Áp dụng công thức:
n = n*(n+1)//2
Code:
n = int(input())
s = n *(n + 1)//2
print("Result:",s)
Bài 6
Xác định bài toán:
Imput: nhập giá trị của n
Output: giá trị của s
Thuật toán:
Áp dụng công thức:
s=n*(n+1)*(2*n+1)//6
Code
n = int(input())
s = n * (n + 1) * (2 * n + 1) // 6
print("Result:",s)
Bài 7
Xác định bài toán:
Imput: nhập giá trị của n
Output: giá trị của s
Thuật toán:
Áp dụng công thức:
s=n^2
Cođe:
n = int(input())
print(n * n)
Bài 8
Xác định bài toán:
Imput nhập giá trị của n
Output: giá trị của s
Thuật toán
Áp dụng công thức:
s=n*(n+1)//2
Cođe:
n = int(input())
s = n * (n + 1) // 2
print(s * s)
Bài 9
Xác định bài toán:
Imput: nhập giá trị của n
Thuật toán:
Áp dụng công thức:
s= n *n * ( n+1) *(n+1) * (2*n*n+2*n-1)//12
Cođe:
n = int(input())
s = n * n * (n + 1) * (n + 1) * (2 * n * n + 2 * n - 1) // 12
print(s)
Bài 10
n = int(input())
s = n * (n + 1) * (n + 2) // 3
print(s)
Bài 11
n = int(input())
s = n / (n + 1.0)
print(s)
Bài 12
n = int(input())
s = n * (n + 3) / (4.0 * (n + 1) * (n +2))
print(s)
Bài 13
n = int(input())
s = n * (n + 2) / ((n + 1) ** 2)
print(s)
Bài 14
p = int(input())
n = int(input())
s = (p ** (n + 1) - 1) // (p - 1)
print(s)
Bài 15
p = int(input())
n = int(input())
s = ((n + 1) * p ** (n + 1)) // (p - 1) - (p ** (n + 1) - 1) // ((p - 1) ** 2)
print(s)
Bài 16
n = int(input())
if n % 2 == 0:
print("N la so chan")
else:
print("N la so le")
Bài 17
n = int(input())
if (n % 3 == 0) and (n % 5 != 0):
print("True")
else:
print("False")
Bài 18
a = int(input())
b = int(input())
res = a
if (res < b):
res = b
print(res)
Bài 19
a = int(input())
b = int(input())
c = int(input())
res = a
if (res > b):
res = b
if (res > c):
res = c
print(res)
bai 20
a= int(input())
b= int(input())
c= int(input())
m= a+b
n= b+c
p= a+c
rmax=m
if rmax < n:
rmax=n
if rmax < p:
rmax = p
print (rmax)