199k views
0 votes
Create a function that takes a two-digit number as an parameter and prints "Ok" in the console if the given string is greater than its reversed digit version. If not, the function will print "Not ok" ○ Test 1: reverseCompare(72) prints "ok" because 72 > 27 ○ reverseCompare(23) prints "Not ok", because 23 is not greater than 32

1 Answer

7 votes

Answer:

Here's a Python function that takes a two-digit number and checks if it's greater than its reversed digit version:

def reverseCompare(num):

if num > int(str(num)[::-1]):

print("Ok")

else:

print("Not ok")

Step-by-step explanation:

  • 'str(num)[::-1]' reverses the string representation of the number using string slicing.
  • 'int(str(num)[::-1])' converts the reversed string back to an integer.
  • The 'if' statement checks if 'num' is greater than the reversed version.
  • If the condition is true, the function prints "Ok", else it prints "Not ok".

Example Usage:
reverseCompare(72) # prints "Ok"

reverseCompare(23) # prints "Not ok"

User Faramarz Afzali
by
8.5k points