While implementing the pectorial function, a question arose.

Asked 2 years ago, Updated 2 years ago, 39 views

def fact(n):
    if <= 1: #If the inequality does not go in, a compilation error will be left.
        return 1
    else:
        return n * fact(n-1)

print(fact(4))

As I wrote in the comment above, there is a compilation error when only '=' without an inequality sign is entered, so can you tell me why?

if문

2022-09-20 20:12

1 Answers

The same is not = in most languages, but ==.

Try ==.

def fact(n):
    if n == 1: #If the inequality does not go in, a compilation error will be left.
        return 1
    else:
        return n * fact(n-1)

print(fact(4))


2022-09-20 20:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.