只是一些背景信息,这段代码有另一个python文件,它测试我的代码,看它是否正常工作,并正确处理所有情况,因为它是一个大学代码/网站
我正在尝试写入csv文件,如果测试它的代码找不到该文件,则显示此错误: “写入错误:错误”
我的代码和输出可以与空闲/讲师期望的输出一起显示在图像中
关于为什么我的代码会显示它所做的事情,以及如何使它与预期的输出相同,有什么想法吗
import csv
def rememberInfo():
name = input("What is your name?")
print()
age = input("How old are you?")
print()
course = input("What course are you on?")
print()
location = input("Where do you live?")
print()
try:
with open('employee_file.csv', mode='w') as employee_file:
employee_writer = csv.writer(employee_file, delimiter=',')
employee_writer.writerow([name, age, course, location])
line = name + "," + age + "," + course + "," + location
print(line)
employee_file.close()
except Exception as e:
print("Error writing:", e)
if __name__ == "__main__":
rememberInfo()
目前没有回答
相关问题 更多 >
编程相关推荐