Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

python - Why am I not getting any value (small, medium or big) when running this funtion? (I think I have to use something else instead of str())

I am importing a class that I am using in this function but that is unrelevant for you. My problem is that carSize2 is being skipped over when I append to my textfile

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!")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

carSize = print("big") prints, but it assigns carSize to None. You have to split into carSize = "big" and print(carSize).


You are printing it in terminal because you use print() which prints it in the terminal. Instead, print in text file using file.write().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...