-2
x=input("Enter the first integer")
y=input("Enter the second integer")

if x>y:
    
    var=x/y #here it show the error 
    print (var)
    print ("here x is  greater than y")
    print ("Normal division is done")
    
elif x<y:
    
    var=x//y
    print (var)
    print ("here y is greater than x")
    print ("Modular division is done")

Here is the output error

Enter the first integer22 Enter the second integer2

Traceback (most recent call last):
  File "modulodiv.py", line 6, in <module>
    str=x/y
TypeError: unsupported operand type(s) for /: 'str' and 'str'

Should i use any other variable or something else and not getting the output as is should compare both the user input and do the normal division or modular division based on which is greater than another

accdias
  • 5,160
  • 3
  • 19
  • 31
Sumeet
  • 1
  • 3
  • It is because the `input()` convert it into a string and `/` operand is not supported for string. You can verify this by printing the type of the variable like `print(type(x))`. You need to explicitly convert it into an integer in your code using typecasting before applying any operand on those variables. – heretolearn Nov 14 '20 at 05:54
  • yes it show string but i tried to take input as integer as- x=int (input ("Enter the first integer")) so now it input as integer and it's works – Sumeet Nov 14 '20 at 05:59

1 Answers1

-1

You haven't declared the values of x or y which is why i think you are getting the error

   x = 2
   y = 1

HamTheMan
  • 49
  • 5
  • "No" the user will enter the values of x an y as i entered here Enter the first integer22 Enter the second integer2 – Sumeet Nov 14 '20 at 05:46