0

I am just a bit confused on why my code of:

print("Welcome to my calculator")



 number_one = int(input("What is your first number: "))

sign = input("Please enter your operator: ")
                   
number_two = int(input("What is your second number: "))

if sign == "+" :
                   print ("Your answer is", number_one + number_two)
if sign == "-" :
                   print("Your answer is", number_one - number_two)
if sign == "/" : print("Your answer is", number_one / number_two)                 

elif sign == "*":  print("Your answer is", number_one * number_two)

else : print("Sorry, i don't understand")

prints out remainders when i use the division operator. I haven't stated a float function and have been told that if you wanted remainders in your answer, you must use it. It's just confusing me on why i am getting remainders even whilst using the integer function?

Shaunak
  • 11
  • 1

1 Answers1

0

When dividing int1/int2 python automatically interprets the result as float if necessary. If you don't want the float value and want to cut it to an integer, you can take int(int1/int2) (or appropriate rounding function). The same result would also be achieved with integer division operator int1//int2.

Otto Hanski
  • 382
  • 1
  • 6