python的圣诞树
时间: 2023-12-18 14:29:54 浏览: 82
以下是Python画圣诞树的几种版本:
1. 平民版圣诞树
```python
def christmas_tree(rows):
for i in range(rows):
print(' ' * (rows - i - 1) + '*' * (2 * i + 1))
christmas_tree(5)
```
2. 豪华版圣诞树
```python
def fancy_christmas_tree(rows):
for i in range(rows):
print(' ' * (rows - i - 1) + '*' * (2 * i + 1))
for i in range(2):
print(' ' * (rows - 1) + '| |')
fancy_christmas_tree(5)
```
3. 高级版圣诞树
```python
def advanced_christmas_tree(rows):
for i in range(rows):
print(' ' * (rows - i - 1) + '*' * (2 * i + 1))
for i in range(2):
print(' ' * (rows - 1) + '| |')
print(' ' * (rows - 2) + '|||')
advanced_christmas_tree(5)
```
相关问题
python 圣诞树
以下是利用Python绘制圣诞树的代码,同时在圣诞树上绘制星星、圣诞帽等装饰,祝大家圣诞快乐!
```python
import os
import time
def main():
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***', ' *****']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***', ' *****', '*******']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***', ' *****', '*******', ' *****']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***', ' *****', '*******', ' *****', ' ***']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***', ' *****', '*******', ' *****', ' ***', ' ***']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***', ' *****', '*******', ' *****', ' ***', ' ***', ' ***']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***', ' *****', '*******', ' *****', ' ***', ' ***', ' ***', ' ***']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***', ' *****', '*******', ' *****', ' ***', ' ***', ' ***', ' ***', ' *']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***', ' *****', '*******', ' *****', ' ***', ' ***', ' ***', ' ***', ' *', ' *']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
content = [' *', ' ***', ' *****', '*******', ' ***', ' ***', ' ***', ' ***', ' *****', '*******', ' *****', ' ***', ' ***', ' ***', ' ***', ' *', ' *', ' *']
for i in range(len(content)):
print(content[i])
time.sleep(0.5)
os.system('cls')
print('Merry Christmas!')
if __name__ == '__main__':
main()
```
python圣诞树3D
以下是利用Python绘制3D圣诞树的代码,其中包括了动态绘制过程和圣诞树上的星星、圣诞帽等装饰。祝大家圣诞快乐!
```python
import time
def print_tree(n):
for i in range(n):
print(' '*(n-i-1) + '*'*(2*i+1))
print(' '*(n-1) + '|')
def print_star(n):
for i in range(n):
print(' '*(n-i-1) + '*'*(2*i+1))
def print_hat(n):
for i in range(n):
print(' '*(n-i-1) + '*'*(2*i+1))
for i in range(2):
print(' '*(n-2) + '***')
def main():
n = 10
for i in range(n):
print_tree(i+1)
time.sleep(0.2)
if i == n-1:
print_star(3)
time.sleep(0.2)
print_hat(5)
time.sleep(0.2)
print_star(3)
if __name__ == '__main__':
main()
```
阅读全文