You are on page 1of 7

Bài 1.

Năm nhuận
thang = int(input())
nam=int(input())
namNhuan = False
ngay = 31
if (nam%4 == 0 and nam%100 == 0 ) or (nam%400 != 0):
namNhuan = True
if (thang == 2):
ngay = 29 if (namNhuan == True) else 28
elif (thang == 4 or thang == 6 or thang == 9 or thang == 11):
ngay = 30
print(ngay)

Chat GPT
def tinh_so_ngay(thang, nam):
if thang == 2:
if nam % 4 == 0 and (nam % 100 != 0 or nam % 400 == 0):
return 29
else:
return 28
elif thang in [4, 6, 9, 11]:
return 30
else:
return 31

thang = int(input())
nam = int(input())

so_ngay = tinh_so_ngay(thang, nam)


print(so_ngay)

Bài 2. Số lớn nhất


a = int(input())
b = int(input())
c = int(input())
d = int(input())
min= min(a, b, c, d)
max = max(a, b, c, d)
print (min)
print (max)
Bài 3. Hai hình chữ nhật giao nhau
x1 = int(input())
y1 = int(input())
w1 = int(input())
h1 = int(input())
x2 = int(input())
y2 = int(input())
w2 = int(input())
h2 = int(input())
if (x1+w1<x2 and x2+w2<x1 or y1+h1<y2 or y2+h2<y1):
print('KHONGGIAONHAU')
else:
print('GIAONHAU')
Bài 4. Tiền điện
a = int(input())
if ( a<=400):
if (a>=0 and a<=50):
S1 = 1678*a
print(S1)
elif (a >=51 and a<=100):
S2= 50*1678 + (a-50)*1734
print(S2)
elif (a>=101 and a<=200):
s3= 50* 1678 + 50* 1734 + (a-100)*2014
print (s3)
elif (a>=201 and a<=300):
s4 = 50* 1678 + 50* 1734 + 100*2014 + (a-200)*2536
print(s4)
else:
s5= 50* 1678 + 50* 1734 + 100*2014 + 100*2536 + (a-300)*2834
print(s5)
else:
s6 = 50* 1678 + 50* 1734 + 100*2014 + 100*2536 + 100*2834 + (a-400)*2927
print(s6)
Bài 5. Tiền điện thoại
a = int(input())#sophutgoi
if (a>=0 and a<= 50):
S= 150000 + a*600
print(S)
elif (51<=a and a<=200):
S= 150000+ 50*600 + (a-50)*400
print(S)
else:
S= 150000 + 50*600 + 150*400 +(a-200)*200

print(S)
Bài 6. BMI
a = int(input())#cannang
b = float(input())#chieucao
BMI= a/(b**2)
if (BMI<18.5):
print("Loai 1: Gay")
if (18.5<= BMI and BMI <=22.9):
print("Loai 2: Binh thuong")
if (23 <= BMI and BMI <=24.9):
print("Loai 3: Tien beo phi")
if (25 <= BMI and BMI <=30):
print ("Loai 4: Beo phi do 1")
if (BMI>30):
print ("Loai 5: Beo phi do 2")

Bài 7. Ngày hôm trước, hôm sau


from datetime import datetime, timedelta
# Nhập ngày, tháng, năm
day = int(input())
month = int(input())
year = int(input())
# Tạo đối tượng datetime từ ngày, tháng, năm
date = datetime(year, month, day)
# Tìm ngày hôm trước
yesterday = date - timedelta(days=1)
# Tìm ngày hôm sau
tomorrow = date + timedelta(days=1)
# In kết quả ra màn hình
print(yesterday.strftime("%d/%m/%Y"))
print(tomorrow.strftime("%d/%m/%Y"))
Bài 8. F1(x) và F2(x)
x = float(input())
import math
if (x>0):
f1 = 3*x + x**(1/2)
print (f"{f1:.3f}")
if (x<=0):
f1 = math.exp(x) +4
print (f"{f1:.3f}")
if (x>=1):
f2= (x*x+1)**(1/2)
print (f"{f2:.3f}")
if (-1<x and x<1):
f2= 3*x+5
print (f"{f2:.3f}")
if (-1>=x):
f2= x*x+2*x-1
print (f"{f2:.3f}")
Bài 9. Phương trình bậc 2
a= int(input())
b= int(input())
c= int(input())
t= b*b-4*a*c
if (a==0):
if (b==0):
print("Phuong trinh vo nghiem!")
else:
x= -c/b
print(f"Phuong trinh co mot nghiem: x = {x:.3f}" )
if (a!=0):
if (t<0):
print("Phuong trinh vo nghiem!")
if (t==0):
v= (-b)/(2*a)
print(f"Phuong trinh co nghiem kep: x1 = x2 = {v:.3f}")
if (t>0):
x1= (-b+(t**(1/2)))/(2*a)
x2= (-b-(t**(1/2)))/(2*a)
print(f"Phuong trinh co 2 nghiem: x1 = {x1:.3f} va x2 = {x2:.3f}")
Bài 10. Số lớn thứ hai
a = int(input())
b = int(input())
c = int(input())
d = int(input())
if(a != b != c != d):
max_number = max(a, b, c, d)
other_numbers = [num for num in [a, b, c, d] if num != max_number]
second_largest = max(other_numbers)
print (second_largest)
if (a == b == c == d):
print (a)
if ( a == b and c == d and a != c and b !=d):
max_number = max (a,c)
other_numbers = [num for num in [a, c, b, d] if num != max_number]
second_largest = max(other_numbers)
print (second_largest)
if ( a==b ==c and a != d):
max_number = max(a, d)
second_largest = min(a, d)
print (second_largest)
if (b==c==d and a!=d):
max_number = max(a, b)
second_largest = min(a, b)
print (second_largest)
Bài 11. Hai đường tròn
x1 = float(input())
y1 = float(input())
r1 = float(input())
x2 = float(input())
y2 = float(input())
r2 = float(input())
distance = ((x1-x2)**2 + (y1-y2)**2)**0.5
if (distance == r1 + r2) or (distance == abs(r2 - r1)):
print("TIEPXUC")
elif distance > r1 + r2:
print("NGOAINHAU")
elif distance + min(r1, r2) < max(r1, r2):
print("TRONGNHAU")
else:
print("GIAONHAU")

You might also like