Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What does this code?
#1
Hello,


What does is this code doing?

def what(n):
 if n<10:
    return n
 else:
    k = what((n//100)*10 + n%10)
    return (k*10 + (n%100) // 10)
thank you.
Yoriz write May-22-2021, 08:38 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
What have you tried? Running the function for a large number of n's may help guess what it does.
ndc85430 likes this post
Reply
#3
(May-22-2021, 10:39 PM)Gribouillis Wrote: What have you tried? Running the function for a large number of n's may help guess what it does.

Just need to explain what the action that the function doing
Reply
#4
It doesn't do anything until you run it. It is much easier to run it than to guess what it does by scrutinizing the code.
Reply
#5
> loop: refers to the repeated execution of the same piece of code when the conditions are met. eg. the while statement

> iterate: refers to visiting each item in the list one by one in a certain order. eg. the for statement.

> traversal: refers to visiting each node in the tree structure according to certain rules, and each node is only visited once. Time complexity: O(n)

> recursive: refers to the behavior of a function constantly calling itself. Time complexity: O(2^n)
for example:
def Fibonacci(n):
    if n == 0:
        return 0;
    elif n == 1:
        return 1;
    return Fibonacci(n-1) + Fibonacci(n-2) # calling function itself
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020