Python写一个生日蛋糕
时间: 2023-05-17 19:05:18 浏览: 60
以下是一个简单的 Python 生日蛋糕代码:
```python
age = input("请输入年龄:")
name = input("请输入姓名:")
print("生日快乐," + name + "!")
print("您已经 " + age + " 岁了!")
cake = """
_____
/ /|
/ / |
/______/ |
| | |
| | |
| | |
| | |
|______|__/
"""
print(cake)
```
您可以根据需要进行修改和调整。祝您生日快乐!
相关问题
python写一个生日蛋糕祝福
好的,以下是一个简单的 Python 程序,可以输出一个生日蛋糕并附上生日祝福:
```python
# 导入必要的模块
import turtle
# 定义画蛋糕的函数
def draw_cake():
# 画上下两层蛋糕
turtle.color("brown")
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
turtle.penup()
turtle.goto(0, 70)
turtle.pendown()
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 画蜡烛
turtle.penup()
turtle.goto(0, 100)
turtle.pendown()
turtle.color("yellow")
turtle.begin_fill()
turtle.circle(10)
turtle.end_fill()
# 输出祝福语
turtle.penup()
turtle.goto(0, 150)
turtle.pendown()
turtle.write("Happy Birthday!", align="center", font=("Arial", 20, "bold"))
# 初始化画布
turtle.setup(400, 400)
turtle.bgcolor("pink")
# 画蛋糕并输出祝福语
draw_cake()
# 点击画布结束程序
turtle.exitonclick()
```
这段程序利用了 Python 的 turtle 模块,可以在画布上绘制图形。执行程序后,会在画布中心绘制一个生日蛋糕,上面有一根蜡烛和生日祝福语。您可以根据需要修改代码中的颜色、字体、祝福语等内容。
用python做一个生日蛋糕
好的,以下是一个用 Python 制作生日蛋糕的示例代码:
```python
def make_cake():
print(" ____ ____ ")
print(" / \~~~/ \\")
print("( @ o o @ )")
print(" \ /~~~\ /")
print(" \__| |__/")
print(" | \___/ |")
print(" \ /")
print(" \______/")
make_cake()
```
这个代码会输出一个生日蛋糕的 ASCII 图案。你可以在其中加入自己的祝福语句,比如:
```python
def make_cake(name):
print(" ____ ____ ")
print(" / \~~~/ \\")
print("( @ o o @ )")
print(" \ /~~~\ /")
print(" \__| |__/")
print(" | \___/ |")
print(" \ /")
print(" \______/")
print(f"Happy birthday, {name}!")
make_cake("Alice")
```
这个代码会输出一个带有名字祝福的生日蛋糕。