diff --git a/String_Palindrome.py b/String_Palindrome.py index 6b8302b6477..ab4103fd863 100644 --- a/String_Palindrome.py +++ b/String_Palindrome.py @@ -1,15 +1,15 @@ # Program to check if a string is palindrome or not -my_str = 'aIbohPhoBiA' +my_str = input().strip() # make it suitable for caseless comparison my_str = my_str.casefold() # reverse the string -rev_str = reversed(my_str) +rev_str = my_str[::-1] # check if the string is equal to its reverse -if list(my_str) == list(rev_str): +if my_str == rev_str: print("The string is a palindrome.") else: print("The string is not a palindrome.") diff --git a/gcd.py b/gcd.py index 0f10da082d7..625bf33a2bd 100644 --- a/gcd.py +++ b/gcd.py @@ -5,10 +5,10 @@ a = int(input("Enter number 1 (a): ")) b = int(input("Enter number 2 (b): ")) -i = 1 -while i <= a and i <= b: - if a % i == 0 and b % i == 0: - gcd = i - i = i + 1 +def calc_GCD(x,y): + if y==0: + return x + return calc_GCD(y,x%y) +gcd=calc_GCD(a,b) print("\nGCD of {0} and {1} = {2}".format(a, b, gcd))