首页 > 解决方案 > 运行此功能时,为什么我没有获得任何价值(小、中或大)?(我想我必须使用其他东西而不是 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!")

标签: python

解决方案


carSize = print("big")打印,但它分配carSizeNone. 你必须分成carSize = "big"print(carSize)


您正在终端中打印它,因为您使用print()which 在终端中打印它。相反,使用file.write().


推荐阅读