forked from edvalin/python-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_python_playground.py
More file actions
67 lines (55 loc) · 1.6 KB
/
my_python_playground.py
File metadata and controls
67 lines (55 loc) · 1.6 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
57
58
59
60
61
62
63
64
65
66
67
# Example of different data types, variables, functions, and loops
# Integer variable
age = 25
# Floating-point variable
height = 1.75
# String variable
name = "John Doe"
# Boolean variable
is_student = True
# Dictionary variable
person1 = {
"name": name,
"age": age,
"height": height,
"is_student": is_student
}
# Dictionary variable2
person2 = {
"name": "Jane Smith",
"age": 30,
"height": 1.65,
"is_student": False
}
# List variable
grades = [80, 90, 75, 95, 85]
# Function to calculate the average of a list
def calculate_average(numbers):
total = sum(numbers)
return total / len(numbers)
# Function to calculate the average of a list
def print_average_result(numbers):
# Calling the calculate_average function and printing the result
average = calculate_average(numbers)
print("Average:", average)
# Function to print all the grades in a list
def list_all_studets_grades(grades):
# Looping over the grades list and printing each grade
print("Grades:")
for grade in grades:
print(grade)
# Function to check if a person is a student
def is_person_student(person):
# Checking if the person is a student and printing the result
if person["is_student"]:
print(person["name"], "is a student.")
else:
print(person["name"], "is not a student.")
# Printing all the grades in the grades list
list_all_studets_grades(grades)
# Printing the average of the grades list
print_average_result(grades)
# Checking if the person is a student
is_person_student(person1)
# Checking if the person is a student
is_person_student(person2)