Agrgumental Error in finding LCM using Python what am i doing wrong

40 Views Asked by At

Hi I am experiencing a issue with writing a code to find lcm of 2 numbers the code is as follows

   def compute_lcm(x, y):

   if x > y:
       greater = x
   else:
       greater = y

   while(True):
       if((greater % x == 0) and (greater % y == 0)):
           lcm = greater
           break
       greater += 1

   return lcm

num1 = input("Number1 ")
num2 = input("Number2 ")

print("The L.C.M. is", compute_lcm(num1, num2))

result:-

PS C:\Users\Amrit Shahi\Desktop> & "C:/Users/Amrit 
Shahi/AppData/Local/Programs/Python/Python310/python.exe" "c:/Users/Amrit 
Shahi/Desktop/Test.py"
Number1 35
Number2 23
Traceback (most recent call last):
  File "c:\Users\Amrit Shahi\Desktop\Test.py", line 19, in <module>
    print("The L.C.M. is", compute_lcm(num1, num2))
  File "c:\Users\Amrit Shahi\Desktop\Test.py", line 9, in compute_lcm
    if((greater % x == 0) and (greater % y == 0)):
TypeError: not all arguments converted during string formatting

To add I am using vs code

0

There are 0 best solutions below