用python编写程序,将字符串“Hello Python”、“BigDate”、“SQL”存入到文件“data.dat”中并读出显示。
时间: 2023-09-12 09:07:40 浏览: 88
: orders) {
System.out.println(order.toString());
}
}
// 订单类
static class Order {
private Map好的,以下是 Python 代码实现:
```python
# 写入数据到文件
with open("data.dat", "w<String, Integer> dishes = new HashMap<>();
private double totalPrice = 0.0;
public void addDish(String dish,") as file:
file.write("Hello Python\n")
file.write("BigData\n")
file.write("SQL\n")
# int quantity) {
dishes.put(dish, quantity);
totalPrice += menu.get(dish) * quantity;
}
public double getTotalPrice() {
return totalPrice;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("订单读取文件中的数据并显示
with open("data.dat", "r") as file:
data = file.read()
print(data)
```
运行结果:
```
Hello Python
BigData
SQL
```
阅读全文