[英]Python: How to get rid of “None”
def ask(x):
while True:
if x == "off":
print("The cash register is closed")
break
elif x == "Bakery products":
ask2 = float(input("Amount:"))
print("Discount 30%. Amount due:", ask2 * 0.7)
continue
elif x == "Dairy products":
ask2 = float(input("Amount:"))
print("Discount 10%. Amount due:", ask2 * 0.1)
continue
else:
ask4 = float(input("Amount:"))
print("Amount due:", ask4)
while True:
ask1 = input("Catergory (off - complete):")
if ask1 == "off":
print("The cash register is closed")
break
elif ask1 == "Bakery products":
ask2 = float(input("Amount:"))
print("Discount 30%. Amount due:", ask2 * 0.7)
print(ask(input("Enter product category:")))
break
elif ask1 == "Dairy products":
ask2 = float(input("Amount:"))
print("Discount 10%. Amount due:", ask2 * 0.1)
print(ask(input("Enter product category:")))
break
else:
ask4 = float(input("Amount:"))
print("Amount due:", ask4)
print(ask(input("Enter product category:")))
break
So, for this code above, at the end when I try to quit it by typing "off", but at the end there is not only "The cash register is closed" printed, but also "None" printed.因此,对于上面的这段代码,最后当我尝试通过键入“关闭”来退出它时,但最后不仅打印了“收银机已关闭”,而且还打印了“无”。 Does anyone know how to get rid of "None"?
有谁知道如何摆脱“无”?
You already have print in the ask
function, you don need it outside it.您已经在
ask
function 中有打印,您不需要它在外面。
def ask(x):
while True:
if x == "off":
print("The cash register is closed")
break
elif x == "Bakery products":
ask2 = float(input("Amount:"))
print("Discount 30%. Amount due:", ask2 * 0.7)
continue
elif x == "Dairy products":
ask2 = float(input("Amount:"))
print("Discount 10%. Amount due:", ask2 * 0.1)
continue
else:
ask4 = float(input("Amount:"))
print("Amount due:", ask4)
while True:
ask1 = input("Catergory (off - complete):")
if ask1 == "off":
print("The cash register is closed")
break
elif ask1 == "Bakery products":
ask2 = float(input("Amount:"))
print("Discount 30%. Amount due:", ask2 * 0.7)
ask(input("Enter product category:"))
break
elif ask1 == "Dairy products":
ask2 = float(input("Amount:"))
print("Discount 10%. Amount due:", ask2 * 0.1)
ask(input("Enter product category:"))
break
else:
ask4 = float(input("Amount:"))
print("Amount due:", ask4)
ask(input("Enter product category:"))
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.