Home > Enterprise >  Adding positive & negative numbers
Adding positive & negative numbers

Time:09-25

This is my 1st time using Stack Overflow so there might be some errors in this post and I'm sorry for it. Anyways, I'm learning my way in Python and looking back in my old math notes, I decided to make a program to solve those problems (for my sister to use to cheat lmao). But I ran into some issues regarding some simple error (for you, maybe) that I can't seem to figure out.

var1 = int(input("Number : "))
var2 = int(input("Number : "))

value = 0
for semi in var1, var2:
    if (semi < 0):
        value  = semi
        area = value / 2
    elif (semi > 0):
        value  = semi
        area = value / 2

print("Value : {}" .format(value))

This is just a part of the code. Now, when I enter, for example, -26 and 25, it gives me -1. What's the error? Is there any way to add a negative and a positive number? Thanks in advance and again, I'm sorry for any mistakes in the post as I'm new here.

Edit: Unused variables are part of something I didn't include here. Sorry for the confusion.

CodePudding user response:

I'm not sure I'm clear what the error is.

-26   25 = -1

I'm not clear what your trying to do because your if blocks are the same, but it seems like your trying to handle negitive number in some way. If your looking for the area then perhaps you want to add the Absolute Value and not have the id statements

value  = abs(semi)

CodePudding user response:

Correct me if I am wrong, but isn´t all you want

var1 = int(input("Number : "))
var2 = int(input("Number : "))
sum=var1 var2
print(¨Value: {}¨.format(sum))

In your code, I have no clue what semi and area even do.

  • Related