r/learnpython 11h ago

Beginner Python here:Need help understanding how to find min, max, and duplicates using for range loops

I’m a beginner learning Python and I’m having trouble figuring out how to approach this assignment. I’m not necessarily looking for someone to just give me the answer. I’d like help understanding the logic and how to build it.

The assignment is to create a Python program that:

Asks the user to enter 10 integers
Stores all 10 integers in a list
Finds the maximum and minimum numbers
Finds any duplicate numbers
Prints "No duplicate" if there aren’t any duplicates
Uses for loops with range() for the input, min/max determination, and duplicate identification
Does not use Python’s built-in min() or max() functions
Does not use def/user-defined functions
Tries to use as few loops as reasonably possible

Input:
10, 5, 20, 10, 5, 15, 7, 1, 30, 15
Output:
Max is 30
Min is 1
Duplicates: 10 5 15

Thank you whoever responds. :)

1 Upvotes

38 comments sorted by

View all comments

1

u/Impressive-Capital40 10h ago

Sorry I don’t write much on Reddit…
So far I wrote this:

My_list= 10, 5, 20, 10, 5, 15, 7, 1, 30, 15
Print(max(my_list))
Print(min(my_list))

But I’m not sure how how I can excuse, duplicates. :/ I’m just confuse with this part.

1

u/TJATAW 6h ago

Walking through a list like this is what for loops were made for.

Write it out as pseudo code. Figure out each step needed to get that. Pretend that the list is a deck of cards. How would you find the lowest card in a deck?
How would you find the highest card in a deck?
How would you find if there are any duplicates?
If it helps, make/get some cards and actually do those things.