I am new to python and trying to create a python3 script that uses the Euclidean Algorithm to find the GCD but I keep on getting an error.
Code:
firstnum = input("Enter the first number: ")
secondnum = input("Enter the second number: ")
if firstnum == secondnum:
print("GCD is: {}").format(firstnum)
quit()
if firstnum > secondnum:
while True:
thirdnum = firstnum % secondnum
firstnum = secondnum
secondnum = thirdnum
if thirdnum == 0:
print("GCD is: {}").format(firstnum)
quit()
else:
continue
if firstnum < secondnum:
while True:
thirdnum = secondnum % firstnum
secondnum = firstnum
firstnum = thirdnum
if thirdnum ==0:
print("GCD is: {}").format(secondnum)
quit()
else:
continue
Error:
Traceback (most recent call last): File "..\Playground\", line 21, in <module>
thirdnum = secondnum % firstnum
TypeError: not all arguments converted during string formatting
If there is a way to fix this error please explain how and why it occurred in the first place. I am also new to string formatting so if you know a more efficient way of printing strings with variables please let me know.