Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我在运行此功能时没有获得任何价值(小、中或大)?(我想我必须用别的东西代替str())_Python - Fatal编程技术网

Python 为什么我在运行此功能时没有获得任何价值(小、中或大)?(我想我必须用别的东西代替str())

Python 为什么我在运行此功能时没有获得任何价值(小、中或大)?(我想我必须用别的东西代替str()),python,Python,我正在导入一个我在此函数中使用的类,但它与您无关。我的问题是,当我附加到文本文件时,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

我正在导入一个我在此函数中使用的类,但它与您无关。我的问题是,当我附加到文本文件时,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(“大”)
打印,但它将
carSize
分配给
None
。您必须分为
carSize=“big”
print(carSize)


您在终端中打印它是因为您使用了在终端中打印它的
print()
。相反,使用
file.write()
carSize=print(“大”)
打印文本文件,但它会将
carSize
指定给
None
。您必须分为
carSize=“big”
print(carSize)



您在终端中打印它是因为您使用了在终端中打印它的
print()
。相反,请使用
file.write()

在文本文件中打印,因为不清楚导入的
大小是什么,所以这很重要。如果将字符串与int进行比较,则会“跳过”

您还应该将该值指定给字符串,而不是调用print函数

carSize = int(input("What kind of car do you have? Please press 1 for small, 2 for medium and 3 for big: "))

if carSize == 1:
    carSize2 = "small"
elif carSize == 2:
    carSize2 = "medium"
elif carSize == 3:
    carSize2 = "big"
else:
    raise Error("Invalid Input")

不清楚导入的
大小
有什么作用,所以这很重要。如果将字符串与int进行比较,则会“跳过”

您还应该将该值指定给字符串,而不是调用print函数

carSize = int(input("What kind of car do you have? Please press 1 for small, 2 for medium and 3 for big: "))

if carSize == 1:
    carSize2 = "small"
elif carSize == 2:
    carSize2 = "medium"
elif carSize == 3:
    carSize2 = "big"
else:
    raise Error("Invalid Input")

如果
print(carSize)
,会发生什么情况?
print()
返回None。。。您希望carSize2=print()
做什么?如果我输入1,它应该输出“small”。如果我输入2,它应该打印出“中等”,然后3打印出“大”,但我没有得到任何这些。carSize2只是被跳过了很难回答这个问题,因为
size
未定义“我正在使用这个类”什么类?如果
print(carSize)
,会发生什么情况?
print()
返回无。。。您希望carSize2=print()做什么?如果我输入1,它应该输出“small”。如果我输入2,它应该打印出“中等”,然后3打印出“大”,但我没有得到任何这些。carSize2只是被跳过了很难回答这个问题,因为
size
没有定义“我正在使用这个类”什么类?它做了一些事情:它打印
“big”
,并将
print
(即
None
)的返回值分配给名称
carSize
。完成。改变答案这仍然不能解决变量被“跳过”的问题这是我的类:类大小:def\uuuu init\uuuuself(self,small:int,medium:int,big:int,big:int,big:int,big:int,big:int,big:int):self.small=small-self.medium=medium-self.big=big=Size=Size(1,2,3)参见@OneCricketeer的答案它做了一些事情:打印
“big”
并将
print
(即
None
)的返回值分配给名称
carSize
。完成。改变答案这仍然不能解决变量被“跳过”的问题这是我的类:类大小:def_uuinit_uu(self,small:int,medium:int,big:int,big:int,big:int):self.small=small-self.medium=medium-self.big=big-Size=Size(1,2,3)参见@OneCricketeer的答案