forked from talkpython/just-enough-python-for-datasci-course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter2.py
More file actions
39 lines (28 loc) · 922 Bytes
/
chapter2.py
File metadata and controls
39 lines (28 loc) · 922 Bytes
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
import marimo
__generated_with = "0.14.17"
app = marimo.App(width="medium")
@app.cell
def _():
return
@app.cell
def _():
def gc_content_percentage(dna_sequence: str) -> float:
"""Calculate the GC content percentage of a DNA sequence."""
# Convert sequence to uppercase for uniformity
dna = dna_sequence.upper()
# Count G and C nucleotides
g_count = dna.count('G')
c_count = dna.count('C')
total_bases = len(dna)
if total_bases == 0:
return 0.0
gc_percent = (g_count + c_count) / total_bases * 100
return gc_percent
# Prompt user for DNA sequence input
if __name__ == "__main__":
user_input = input("Enter a DNA sequence: ").strip()
percentage = gc_content_percentage(user_input)
print(f"GC content: {percentage:.2f}%")
return
if __name__ == "__main__":
app.run()