Share 99 bottles of beer python

trihao792

New member
`` `
# 99 chai bia trong Python

## Giới thiệu

99 chai bia là một bài hát uống truyền thống thường được hát trong các vòng.Bài hát nói về một người đang đếm số lượng chai bia mà họ còn lại.Bài hát bắt đầu với 99 chai bia và kết thúc với 1 chai bia.

## Mật mã

Mã sau đây cho thấy cách in lời bài hát của 99 chai bia trong Python:

`` `Python
def chín mươi_nine_bottles_of_beer ():
"" "In lời bài hát của 99 chai bia." ""

Đối với I trong phạm vi (99, 0, -1):
Nếu i == 1:
In ("1 chai bia trên tường, 1 chai bia.")
In ("Cán nó xuống và vượt qua nó, không còn chai bia trên tường.")
khác:
in (f "{i} chai bia trên tường, {i} chai bia.")
In ("Hãy hạ một cái xuống và vượt qua nó, {i - 1} chai bia trên tường.")

Nếu __name__ == "__main__":
Chín mươi_nine_bottles_of_beer ()
`` `

## đầu ra

Khi mã được chạy, đầu ra sau được tạo ra:

`` `
99 chai bia trên tường, 99 chai bia.
Lấy một xuống và vượt qua nó, 98 chai bia trên tường.

98 chai bia trên tường, 98 chai bia.
Lấy một xuống và vượt qua nó, 97 chai bia trên tường.

...

1 chai bia trên tường, 1 chai bia.
Cất nó xuống và vượt qua nó, không còn chai bia trên tường.
`` `

## Phần kết luận

Mã này có thể dễ dàng sửa đổi để thay đổi số lượng chai bia hoặc để thêm các câu khác vào bài hát.

## hashtags

* #99bottlesofbeer
* #drovedsong
* #Python
* #Programming
* #vui vẻ
`` `
=======================================
```
# 99 Bottles of Beer in Python

## Introduction

99 Bottles of Beer is a traditional drinking song that is often sung in rounds. The song is about a person who is counting down the number of bottles of beer they have left. The song starts with 99 bottles of beer and ends with 1 bottle of beer.

## The Code

The following code shows how to print the lyrics of 99 Bottles of Beer in Python:

```python
def ninety_nine_bottles_of_beer():
"""Prints the lyrics of 99 Bottles of Beer."""

for i in range(99, 0, -1):
if i == 1:
print("1 bottle of beer on the wall, 1 bottle of beer.")
print("Take it down and pass it around, no more bottles of beer on the wall.")
else:
print(f"{i} bottles of beer on the wall, {i} bottles of beer.")
print("Take one down and pass it around, {i - 1} bottles of beer on the wall.")

if __name__ == "__main__":
ninety_nine_bottles_of_beer()
```

## Output

When the code is run, the following output is produced:

```
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

...

1 bottle of beer on the wall, 1 bottle of beer.
Take it down and pass it around, no more bottles of beer on the wall.
```

## Conclusion

This code can be easily modified to change the number of bottles of beer or to add other verses to the song.

## Hashtags

* #99bottlesofbeer
* #drinkingsong
* #Python
* #Programming
* #fun
```
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top