This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bai1(): | |
print("Bài 1: Viết hàm Python tìm số lớn nhất trong 3 số") | |
a = float(input("Nhập số thứ nhất: ")) | |
b = float(input("Nhập số thứ hai: ")) | |
c = float(input("Nhập số thứ ba: ")) | |
print("Số lớn nhất là:", max(a, b, c)) | |
def bai2(): | |
print("Bài 2: Viết hàm Python tính tổng tất cả các số trong danh sách") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a) Convert two lists into a dictionary | |
print('a.') | |
keys = ["id", "name", "age"] | |
values = [101, "Alice", 20] | |
my_dict = dict(zip(keys, values)) | |
print("Converted dictionary:", my_dict) | |
# b) Merge two dictionaries | |
print('b.') | |
dict1 = {"a": 1, "b": 2} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Write a Python program to sum all the items in a list. | |
def bai1(): | |
print("B1: Tổng phần tử ") | |
def sum_list(i): | |
sum_numbers = 0 | |
for x in i: | |
sum_numbers += x | |
return sum_numbers | |
b1 = input("Nhập các số (cách nhau bởi dấu cách): ") | |
i = [int(x) for x in b1.split()] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#1.Guess The Number | |
import random | |
money = 100 | |
win = 0 | |
lose = 0 | |
print("1. Guess The Number") | |
while money >= 5: | |
print(f"Bạn hiện có {money}$") | |
while True: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#1.Guess The Number | |
import random | |
money = 100 | |
win = 0 | |
lose = 0 | |
print("1. Guess The Number") | |
while money >= 5: | |
print(f"Bạn hiện có {money}$") | |
while True: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Bai 1 Write a Python program to calculate the length of a string. | |
def bai1(): | |
print('Bai 1: Tính độ dài của một chuỗi') | |
def string_length(s): | |
return len(s) | |
user_input = input("Enter a string: ") | |
length = string_length(user_input) | |
print(f"String: {user_input}") | |
print(f"The length of the string is: {length}") |