用python写一个生日快乐的html文件
时间: 2024-05-21 22:14:54 浏览: 79
生日快乐.html
以下是用 Python 写一个生日快乐的 HTML 文件的示例代码:
```python
html_template = """
<!DOCTYPE html>
<html>
<head>
<title>Happy Birthday!</title>
<style>
body {
background-color: #f7dcbb;
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
font-size: 48px;
margin-top: 100px;
}
p {
font-size: 24px;
margin-top: 20px;
}
img {
width: 300px;
margin-top: 50px;
}
</style>
</head>
<body>
<h1>Happy Birthday!</h1>
<p>Wishing you a day filled with happiness and a year filled with joy.</p>
<img src="https://i.imgur.com/7ymA3Sb.png" alt="birthday cake">
</body>
</html>
"""
with open("happy_birthday.html", "w") as f:
f.write(html_template)
```
运行以上代码后,会在当前目录下生成一个名为 `happy_birthday.html` 的文件,内容为生日快乐的 HTML 页面。可以用浏览器打开该文件,查看效果。
阅读全文