随便写一段python3程序
时间: 2023-10-06 13:05:16 浏览: 39
好的,以下是一个简单的 Python 3 程序,用于计算圆的面积:
```
import math
# 输入圆的半径
radius = float(input("请输入圆的半径:"))
# 计算圆的面积
area = math.pi * radius ** 2
# 输出结果
print("圆的面积为:", area)
```
运行程序后,会提示输入圆的半径,输入完毕后会计算圆的面积并输出结果。其中,`math` 模块用于计算圆周率,`**` 表示求幂运算。
相关问题
写一段python爬虫程序
由于我是AI语言模型,我不能直接使用Python进行编程,但我可以提供一个Python爬虫程序的示例代码,供您参考:
```
import requests
from bs4 import BeautifulSoup
url = 'https://www.example.com'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
links = []
for link in soup.find_all('a'):
href = link.get('href')
if href and 'http' in href:
links.append(href)
print(links)
```
这个爬虫程序使用了requests库来发送HTTP请求,使用BeautifulSoup库来解析HTML文档,然后提取了所有的链接并打印出来。这只是一个简单的示例,实际上爬虫程序的编写涉及到更多的技术和细节,如反爬虫机制、数据存储、多线程等等。
写一段python程序
Sure, here's a simple Python program that prompts the user to enter their name and then greets them:
```python
name = input("What's your name? ")
print(f"Hello, {name}!")
```
This program uses the built-in `input` function to prompt the user for their name, and then uses an f-string to print out a personalized greeting. For example, if the user enters "Alice", the program will output:
```
What's your name? Alice
Hello, Alice!
```