File tree Expand file tree Collapse file tree 4 files changed +84
-0
lines changed Expand file tree Collapse file tree 4 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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 )} " )
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments