-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
56 lines (38 loc) · 1.11 KB
/
functions.py
File metadata and controls
56 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
functions.py
Demonstrates how to define and use functions in Python
with simple, practical examples.
"""
# Basic function with no parameters
def say_hello():
print("Hello from a function!")
# Function with one parameter
def greet(name):
return f"Hello, {name}!"
# Function with multiple parameters
def add_numbers(a, b):
return a + b
# Function with a default parameter
def introduce(name, country="India"):
return f"My name is {name} and I am from {country}."
# Function that uses a list
def count_skills(skills):
return len(skills)
# Function with a simple decision (if/else)
def is_adult(age):
if age >= 18:
return True
return False
# Calling the functions and printing results
if __name__ == "__main__":
say_hello()
message = greet("Subham")
print(message)
result = add_numbers(10, 5)
print(f"10 + 5 = {result}")
intro = introduce("Subham")
print(intro)
skills = ["Python", "HTML", "Git", "AI Basics", "Automation with Python"]
print(f"Number of skills: {count_skills(skills)}")
age = 24
print(f"Is {age} an adult? {is_adult(age)}")