Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
session_14_code_testing3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reece Singh
session_14_code_testing3
Commits
daf96e3f
Commit
daf96e3f
authored
8 months ago
by
Lowri Williams
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
ebc5a7d3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sample_code.py
+68
-0
68 additions, 0 deletions
sample_code.py
with
68 additions
and
0 deletions
sample_code.py
0 → 100644
+
68
−
0
View file @
daf96e3f
# sample_code.py
def
add
(
a
,
b
):
"""
Add two numbers.
"""
return
a
+
b
def
subtract
(
a
,
b
):
"""
Subtract the second number from the first.
"""
return
a
-
b
def
multiply
(
a
,
b
):
"""
Multiply two numbers.
"""
return
a
*
b
def
divide
(
a
,
b
):
"""
Divide the first number by the second, handling division by zero.
"""
if
b
==
0
:
return
"
Cannot divide by zero
"
return
a
/
b
def
power
(
base
,
exponent
):
"""
Raise a base number to an exponent.
"""
return
base
**
exponent
def
is_palindrome
(
s
):
"""
Check if a string is a palindrome (ignores case and spaces).
"""
s
=
s
.
replace
(
"
"
,
""
).
lower
()
return
s
==
s
[::
-
1
]
def
count_vowels
(
s
):
"""
Count the number of vowels in a string.
"""
vowels
=
"
aeiouAEIOU
"
return
sum
(
1
for
char
in
s
if
char
in
vowels
)
def
factorial
(
n
):
"""
Calculate the factorial of a non-negative integer.
"""
if
n
<
0
:
return
"
Invalid input - must be a non-negative integer
"
elif
n
==
0
or
n
==
1
:
return
1
else
:
result
=
1
for
i
in
range
(
2
,
n
+
1
):
result
*=
i
return
result
def
fibonacci
(
n
):
"""
Generate the nth Fibonacci number.
"""
if
n
<
0
:
return
"
Invalid input - must be a non-negative integer
"
elif
n
==
0
:
return
0
elif
n
==
1
:
return
1
else
:
a
,
b
=
0
,
1
for
_
in
range
(
2
,
n
+
1
):
a
,
b
=
b
,
a
+
b
return
b
def
is_prime
(
n
):
"""
Check if a number is a prime number.
"""
if
n
<=
1
:
return
False
for
i
in
range
(
2
,
int
(
n
**
0.5
)
+
1
):
if
n
%
i
==
0
:
return
False
return
True
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment