[Python] Beginner Python: Is my logic for finding the max in a list correct? (Personal...

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    This is Veerakumar Ashokan

    I'm a beginner in Python, currently working through the Python for Everybody on Coursera. I just hit a really exciting point in my learning: I wrote my first loop-based code by logical thinking.

    The task I tried was to find the maximum value in a list. I paused the video and challenged myself to write it from scratch. Here's the code I came up with:

    numbers = [1,3,5,7,9]
    current_max = numbers[0]
    print("The Current Max is",current_max)

    for i in numbers:
    if i > current_max:
    current_max = i
    print("Checking...", current_max)

    print ("The Final Max is,", current_max )


    (1) Start by assuming the first number is the max.

    (2) Loop through the list.

    (3) If you find something bigger, update the max.

    (4) Print updates along the way.

    It seems to work fine — but I wanted to check the following:

    (a) Is this a good logical approach for beginners?

    (b) Are there any pitfalls in this pattern I should watch out for?

    (c) Are there more advanced ways to do this, once I move beyond the basics?

    I know this isn’t a “hard” problem, but this felt like a big step for me — the first time I solved something with my own logic. If anyone else remembers this stage of learning, I'd love to hear how you approached your first problems too.

    Thanks in advance for your time and feedback!

    Continue reading...

Compartilhe esta Página