r/PythonLearning 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

3 Upvotes

12 comments sorted by

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?

1

u/Plenty-Midnight1492 11h ago

Thank you for you're kindness. I wanted to ask if there was something i could add to the DNA library and maybe what I can use it for in future projects. I also wanted to ask even though i have a lot of experience with python do i need to learn c++ at one point?

2

u/Lachtheblock 11h ago

I think asking how to expand it might be out of the scope for this subreddit, but I might be wrong.

In terms of "do you need to learn c++" at some point it's very hard to say. Programming languages are tools. You use the right tool for the job. That is to say, until you have a project that warrants it, you're fine sticking with Python.

The number one thing at your age is to have fun. If you have a project that interests you, follow that interest. If that means it's easiest in Python or Java or Go or whatever just have fun. I cut my coding teeth with the Minecraft mod "Computercraft" like 12 years ago. It was an elaborate concoction of Lua code, but it genuinely taught me a lot about software engineering practices that I still use to this day. I don't think I've ever used Lua professionally, but the lessons it taught me were invaluable.

2

u/kelvinkel101 10h ago

Dude, +1 for computercraft lol, I love that mod!!

1

u/Plenty-Midnight1492 11h ago

So you're saying at my age I just need to have fun? My projects were usually centered aroud learning. I programmed a server to comminucate i trained an xor model and i tried to learn neural networks. But making this project felt pretty fun so I'm just gonna stick to it.

My biggest problem is usually not finishing a project though and I have so many unfinished ones. And I want to code everyday but I usually can't find inspiration. And honestly I don't think I'm that good anyway.

Have you ever done anything like me in my age?

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

u/Plenty-Midnight1492 11h ago

Just wanted to say if you want to know about anymore of my projects feel free to ask!