Python Basic

Bài tập 1

Viết chương trình tìm ước chung lớn nhất của 2 số

Bài tập 2

Bố cho Lan 20 viên kẹo Cứ 3 vỏ kẹo thì đổi 1 viên kẹo mới. Viết chương trình tính số kẹo mà Lan có thể ăn được bao nhiêu viên kẹo.

Bài tập 3

Viết chương trình cho bài toán đong nước cho 2 bình rỗng x và y đổ qua đổ lại làm sao cho đong được z lít nước (z = n * ucln(x, y))

Ví dụ:

x = 5, y = 3, z = 4

x = 7, y = 5, z = 4

x = 8, y = 6, z = 4

x = 12, y = 7, z = 10

Bài tập 4

In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are lots of ways to win: (1, 6), (2, 5), etc. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people’s eyes glaze over at the first mention of mathematics, your challenge is to write a program that demonstrates the futility of playing the game. Your program should take as input the amount of money that the player wants to put into the pot, and play the game until the pot is empty. At that point, the program should print the number of rolls it took to break the player, as well as maximum amount of money in the pot.