Skip to content

Commit 7a9f390

Browse files
committed
Finishing Function
1 parent cd06c05 commit 7a9f390

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

basics/Function/Args&PM.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'''
2+
Arguments and Parameters
3+
4+
Syntax
5+
6+
def function_name(parameters):
7+
statements
8+
9+
function_name(arguments)
10+
'''
11+
12+
def sayHello(name): #Parameters
13+
print("Hello " + name) #Statements
14+
15+
def multiply(a,b): # Multiple Parameters
16+
print(f"{a*b}")
17+
18+
sayHello("John") #Arguments
19+
multiply(2,3)

basics/Function/challenge.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''
2+
- **Challenge**
3+
4+
**Square a Number** with **Function w/ Parameter**
5+
6+
Create a Program that will make the user input a number the program should **Square** the number then print it
7+
8+
**Condition**
9+
10+
- You must create a function called **square()** then pass the number inside it then return the squared value
11+
- **Print** the square value outside of the function
12+
13+
**Example**
14+
15+
Input : 5
16+
Output : 25
17+
'''
18+
19+
def square(num):
20+
return num * num
21+
22+
num = int(input("Enter a number: "))
23+
print(f"The square of {num} is {square(num)}")

basics/Function/function.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'''
2+
Creating a Function
3+
4+
Syntax
5+
6+
def function_name(parameters):
7+
statements
8+
9+
10+
'''
11+
12+
#Creating a Function
13+
def say_hello():
14+
print("Hello")
15+
16+
say_hello() #Calling a Function

basics/Function/return.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''
2+
Return Function Statement
3+
4+
Syntax:
5+
6+
def function_name(parameters):
7+
statements
8+
return statement
9+
10+
function_name(arguments)
11+
'''
12+
13+
def add(n1,n2):
14+
return n1 + n2
15+
16+
sum = add(2,3) # Assigning the return value to a variable
17+
print(sum) # Printing the variable
18+
19+
def isLegalAge(age):
20+
if age >= 18:
21+
return True
22+
else:
23+
return False
24+
25+
isLegal = isLegalAge(17)
26+
print(isLegal)

0 commit comments

Comments
 (0)