Python 如何将负值存储为零?

Python 如何将负值存储为零?,python,python-3.x,Python,Python 3.x,如何在python上存储一个负值为零的值 例如: Enter a number:3 Enter a number:4 3 - 4 = 0 答案实际上是-1,但因为答案是否定的,所以答案存储为零 请帮忙 只需使用条件表达式: result = 3 - 4 total = 0 if result < 0 else result result=3-4 如果结果

如何在python上存储一个负值为零的值

例如:

Enter a number:3
Enter a number:4
3 - 4 = 0
答案实际上是-1,但因为答案是否定的,所以答案存储为零


请帮忙

只需使用条件表达式:

result = 3 - 4
total = 0 if result < 0 else result
result=3-4
如果结果<0,则总计=0其他结果
您可以使用内置的:


“已存储”或“您希望存储”为零?我假设是后者,但我不得不把你的问题读了好几遍。我想把它存储起来。哈哈!;)+1.但是OP想要答案:)谢谢。我将更新答案。我需要使用if语句。例如:if(a或b<0):#存储为0@PolliEster为什么“需要”使用
if
语句?这似乎不是一个合理的要求。它来自哪里?你还有什么其他要求没有说明吗?
a = 3
b = 4
total = max(0, a-b) # total == 0
total = max(0, b-a) # total == 1