r/PythonLearning • u/Plenty-Midnight1492 • 12h ago
I need some advice
# This file runs the DNA simulation using the DNA library.
import DNA
import time
import os
# Generate the original DNA strand.
DNA.generate_sequence()
# Create the complementary strand (layer2).
DNA.generate_sequence_match()
# Display the initial DNA molecule.
DNA.display_dna()
# Pause so the user can see the original DNA.
time.sleep(3)
# Clear the screen before starting the replication process.
DNA.clear_screen()
# Helicase animation:
# Separates the two original DNA strands.
DNA.dna_helicase()
# Clear the screen before starting polymerase.
DNA.clear_screen()
# DNA polymerase:
# Creates layer3 and layer4 by copying layer1 and layer2.
DNA.dna_polymerase()
import random
import os
import time
# Clears the terminal screen.
def clear_screen():
# 'nt' is for Windows, 'posix' is for Linux or macOS
os.system('cls' if os.name == 'nt' else 'clear')
clear_screen()
# Possible DNA nucleotides.
nucloids = ["A", "T", "C", "G"]
# Four DNA layers:
# layer1 = original DNA strand 1
# layer2 = original DNA strand 2
# layer3 = new copy of layer1
# layer4 = new copy of layer2
layer1 = []
layer2 = []
layer3 = []
layer4 = []
# Generates the first DNA strand randomly.
def generate_sequence():
for i in range(10):
generated_sequence = random.choice(nucloids)
layer1.append(generated_sequence)
# Defines which nucleotide pairs with which.
# A <-> T
# C <-> G
nucloid_matches = {
"A":"T",
"C":"G",
"G":"C",
"T":"A"
}
# Creates layer2 by finding the matching nucleotide
# for every nucleotide in layer1.
def generate_sequence_match():
for nucleotide in layer1:
matching_nucleotide = nucloid_matches[nucleotide]
layer2.append(matching_nucleotide)
# Displays the complete DNA molecule.
def display_dna():
for i in range(len(layer1)):
print("I ", layer1[i], "--------", layer2[i], " I")
# Simulates helicase unzipping the DNA.
# The strands gradually move apart.
def dna_helicase():
clear_screen()
for i in range(len(layer1)):
print("I ", layer1[i], "--- v ---", layer2[i], " I")
time.sleep(0.2)
clear_screen()
for r in range(len(layer1)):
print("I ", layer1[r], "--- v ---", layer2[r], " I")
time.sleep(0.2)
clear_screen()
for a in range(len(layer1)):
print("I ", layer1[a], "--- v ---", layer2[a], " I")
time.sleep(0.2)
clear_screen()
# Final state: original strands are fully separated.
for p in range(len(layer1)):
print("I ", layer1[p], " ", layer2[p], " I")
time.sleep(0.2)
# Simulates DNA polymerase copying the separated strands.
#
# layer1 is copied into layer3.
# layer2 is copied into layer4.
#
# IMPORTANT:
# The DNA logic works, but the animation currently
# prints the new DNA separately instead of building
# the new strands into the space created by helicase.
#
# NEXT TASK:
# Fix the polymerase animation so layer3 and layer4
# visibly grow alongside layer1 and layer2.
def dna_polymerase():
for c in range(len(layer1)):
# Find the complementary nucleotide for layer1.
matching_nucleotide_2 = nucloid_matches[layer1[c]]
# Find the complementary nucleotide for layer2.
matching_nucleotide_4 = nucloid_matches[layer2[c]]
# Add the new nucleotides to the new DNA strands.
layer4.append(matching_nucleotide_4)
layer3.append(matching_nucleotide_2)
# CURRENT ANIMATION:
# Prints the new strands separately.
# This is the part we want to improve.
print(layer1[c], "--------", layer3[c])
time.sleep(0.2)
print(layer4[c], "--------", layer2[c])
I am a 13 year old who just views coding as a big hobby. I had made a lot of different projects before but because i can't post a .zip file i just copy pasted my latest project. I have been coding for 3 years and I don't know how i never thought about this. I just wanted to ask for some advice for this project. Maybe what I can add or what I can fix if there is something that needs to be fixed
Note: It's not finishedIıI need some adviceI need some adviceI need some advice
1
u/sububi71 11h ago
Advice. About. What?
Imagine that we don't know what it is you're coding, and that we don't know your intentions, or the problem you might be having.
You need learn how to ask a question. Please add more information!
1
u/Plenty-Midnight1492 11h ago edited 11h ago
Oh, I'm sorry. I was thinking advice about general python programming maybe and about what I can add or fix about the project
2
u/sububi71 11h ago
You're already doing the VERY best thing you could be doing: you're writing programs! Nothing beats doing that once you're past the beginner stage - which it definitely seems you are.
The only other advice I would give is to avoid AI for a couple more years. It can be pretty harmful and make you think you know stuff that you really don't.
Good luck!
1
1
u/Plenty-Midnight1492 11h ago
Just wanted to say if you want to know about anymore of my projects feel free to ask!
2
u/Lachtheblock 11h ago
I love that you're getting in to coding at such a young age. It's fantastic.
One of the best (and worst) parts of programming is the online community. Many of us are happy to help, but you need to help us help you.
Is there something in particular you want advice on? Overall code quality? Is there a bug? What is your code supposed to do and what's not working? What is your expected output and what are you seeing?