python - 运行此功能时,为什么我没有获得任何价值(小、中或大)?(我想我必须使用其他东西而不是 str())
问题描述
我正在导入一个在此函数中使用的类,但这与您无关。我的问题是当我附加到我的文本文件时 carSize2 被跳过
file = open("data", "a")
number = input("What is your license number?: ")
name = input("What is your name?: ")
carSize = input("What kind of car do you have? Please press 1 for small, 2 for medium and 3 for big: ")
carSize2 = str()
if carSize == size.small:
carSize2=print("small")
elif carSize==size.medium:
carSize2= print("medium")
elif carSize==size.big:
carSize2= print("big")
startHour = input("Input the hour when you entered the parking lot(in 24h time please, no leading zeroes): ")
startMinute = input("Input the minute when you entered the parking lot: ")
endHour = input("Input the hour when you exited the parking lot(in 24h time please, no leading zeroes): ")
endMinute = input("Input the hour when you exited the parking lot: ")
file.write(
number + " " + carSize2 + " " + name + " " + "you entered the parking lot at " + startHour + ":" + startMinute + " and left at " + endHour + ":" + endMinute)
print("OK!")
解决方案
carSize = print("big")
打印,但它分配carSize
给None
. 你必须分成carSize = "big"
和print(carSize)
。
您正在终端中打印它,因为您使用print()
which 在终端中打印它。相反,使用file.write()
.
推荐阅读
- google-pay - Google Pay 如何判断用户的付款方式?
- javascript - 附加的行组作为 jquery 响应不尊重表条带表样式
- r - 使用 poly2nb() 的邻居列表适用于 2004 年人口普查 shapefile,但不适用于 2011 年
- php - 使用自定义验证扩展()时,获取方法 Illuminate\Validation\Validator::validateError 不存在
- grafana - 使用 Helm 导入仪表板,将 Sidecar 用于仪表板
- javascript - 智能锁屏不适用于移动触摸(javascript 和 jquery)
- reactjs - 在 typescript(sharepoint 现代 ui)项目中使用 webpack 魔术注释
- java - 使用 PDFBOX PreflightParser for PDDocument 验证 PDF
- php - 如何比较 int 和时间戳列(Laravel 雄辩)?
- c# - 无法将文件“<>.mdf”附加为数据库“<>”