English

The code given below accepts a number as an argument and returns the reverse number. Observe the following code carefully and rewrite it after removing all syntax and logical errors.

Advertisements

Question

The code given below accepts a number as an argument and returns the reverse number. Observe the following code carefully and rewrite it after removing all syntax and logical errors. Underline all the corrections made.

define revNumber (num) :
      rev = 0
      rem = 0
      While num > 0:
            rem ==num %10
            rev = rev*10 + rem
            num = num//10
            return rev
print (revNumber (1234))
Short/Brief Note
Advertisements

Solution

def revNumber (num) :
          rev = 0
          rem = 0
          while num > 0:
               rem =num %10
               rev = rev*10 + rem
               num = num//10
       return rev
print (revNumber (1234))
shaalaa.com
Syntax Errors in Python
  Is there an error in this question or solution?
2023-2024 (March) Board Sample Paper
Advertisements
Share
Notifications



      Forgot password?
Use app×