156k views
4 votes
Does python allow if statements to occur within the definition of a function

User Gcharita
by
7.6k points

1 Answer

3 votes

Answer: Yes python allows an if statement to occur within the definition of a function.

Explanation:

for example: write a Python function to tell whether the number is positive or not. The function should return Yes if positive and No if negative.

def function_positive_negative(x):

if x>0:

return "Yes"

else:

return "No"

def main():

x=input("enter a number")

print(function_positive_negative(x))

User Ooba Elda
by
8.1k points

No related questions found