python随机生成外国地址
时间: 2023-07-25 14:28:29 浏览: 115
下面是一个使用Python随机生成外国地址的示例代码:
```python
import random
# 国家、州、城市、街道、邮编的随机选项
countries = ["USA", "UK", "Canada", "Australia"]
states = ["California", "New York", "Texas", "Florida", "London", "Sydney", "Ontario"]
cities = ["Los Angeles", "New York City", "Dallas", "Toronto", "Melbourne"]
streets = ["Main St", "High St", "Broadway", "Oxford St", "Bourke St"]
zipcodes = ["10001", "90210", "M5V 1J2", "SW1A 1AA", "2000"]
# 生成随机地址
country = random.choice(countries)
state = random.choice(states)
city = random.choice(cities)
street = random.choice(streets)
zipcode = random.choice(zipcodes)
# 打印随机地址
print(f"{street}, {city}, {state}, {country}, {zipcode}")
```
这个示例代码会从预定义的选项中随机选取国家、州、城市、街道和邮编,然后将它们拼接成一个随机的外国地址并打印出来。你可以根据需要修改选项或添加更多选项来生成不同的地址。
相关推荐
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)