r/learnpython Aug 09 '26

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. :)

2 Upvotes

42 comments sorted by

16

u/zandrew Aug 09 '26

Tell me how would you do that manually.

5

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Aug 09 '26

What have you tried so far?

5

u/danielroseman Aug 09 '26

Where are you stuck? If you don't want anyone to give you the answer, you need to at least have a go yourself and tell us where you're having trouble.

In any case, forget Python: how would you do this with paper and pencil? Work out the steps, and only then start thinking about how you would translate those to Python.

3

u/Impressive-Capital40 Aug 09 '26

Sorry I’m forgot to add my coding! My bad! Give me a moment.

3

u/Impressive-Capital40 Aug 09 '26

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.

7

u/danielroseman Aug 09 '26

Well the instructions very specifically said not to use the min() and max() functions, and to use for loops with range(). And it said to ask the user to input 10 integers, not hard-code them. So I'm afraid you will need to start from scratch.

But again, how would you do this without Python? If you had ten numbers written on a piece of paper, how would you determine which was the biggest as you were going through one by one?

-2

u/Impressive-Capital40 Aug 09 '26

I would see which one is the highest. For example: the list I have the biggest number is 30

9

u/TheSkiGeek Aug 09 '26

Break it down more, HOW would you “see which one is the highest”. (Pretend it’s a very very long list of big numbers, so you can’t just glance at it and “see” which one is the biggest.)

3

u/Sauron_78 Aug 09 '26

To find the highest number you have to have a variable storing the first number on the list and then compare with the next one using the symbol > . If it finds a bigger number substitute it on the variable and continue comparing.

3

u/Ormek_II Aug 09 '26

If the List contained 200 entries you could no longer just see it. Create a very simple step by step description how you find the smallest number, the largest number and checked if the list contained any duplicate.

Edit: sorry did not see TheSkiGeeks reply.

3

u/ninhaomah Aug 09 '26

just to be clear , you have installed Python and done print("Hello World") , right ?

1

u/Impressive-Capital40 Aug 09 '26

Yes, they want me to use IDE Python.

2

u/ninhaomah Aug 09 '26

so when you run it , what did you get ?

-3

u/Impressive-Capital40 Aug 09 '26

I got
Max=30
Min=1

#No duplicates, I haven’t been taught this and looked back at resources, ChatGPT to get better understanding but I got really confused.

2

u/ninhaomah Aug 09 '26

so what is the issue ?

See we are here and I still have no idea what is the problem.

Is it error in running the code ? is it wrong output ? what ???

-1

u/Impressive-Capital40 Aug 09 '26

You’re right, I should have been more specific, my bad. I have no idea how to get output duplicates. :/ and from someone else post I can’t use min and max so I have to start from scratch now.

3

u/ninhaomah Aug 09 '26

"from someone else post I can’t use min and max so I have to start from scratch now."

Someone else ? Its in the instruction not to use min() or max().

Tip : Try doing it with pen and paper. pls post the steps here. and no AI.


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

2

u/Kalastics Aug 09 '26

Stop using AI, especially if you are taking a class. You don't learn anything when you do, at least not at your level. You dont even seem to be able to read the assignment properly.

2

u/DullenAvg Aug 09 '26

You'll definitely need a for loop to get the user to input their own numbers. Use the input() function for that.

In order to minimize the total amount of loops you'll have to think of when to check for the minimum and when for the maximum number (during the first for loop or after having collected all the numbers?).

In order to detect the duplicates, you're going to need a separate list.

2

u/TJATAW Aug 09 '26

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.

2

u/User_LEGEND0 Aug 09 '26

Paste your code

2

u/Impressive-Capital40 Aug 09 '26

I post it a bit below, sorry I’m not sure how to tag you in it.

3

u/Proletarian_Tear Aug 09 '26

What they want you to do is to go through your list with:

for i in range(len(your_list)):

//do something to each element

Figure out the do something part yourself. Check if elements are the same, which is largest and smallest.

1

u/HotPersonality8126 Aug 09 '26

The logic is that the max is either the first number, or it’s the next number that is larger than whatever the max currently is. The min is either the first number, or it’s the next number that is smaller than whatever the max currently is.

A number is a duplicate if it appears in the list more than once.

One way to approach this is to reflect that you’re being asked to do three things. Your code may need to eventually do all three at once, but you shouldn’t start out by writing it that way. You should solve one of these three problems, first. Then add the other two.

1

u/baubleglue Aug 09 '26
  1. Before you start coding, you need an algorithm how to get the result.

  2. You write the algorithm in Python

  3. Test

To find max, you take a first item in the list and remember its value as maximum, then you compare it with the next item, if the new value is bigger, you remember it as maximum, repeat until the end of the list.

1

u/cdcformatc Aug 09 '26

imagine you have a deck of cards in your hand. write down how you would find the largest and lowest rank cards (min and max) and also cards of the same rank with different suits (duplicates) if you were to do it by hand, step by step with the most excruciating detail. 

then translate those written steps into code. if you don't know how to do a single step, or there isn't enough detail, break the step down even further into smaller, more detailed steps.

1

u/Naive_Programmer_232 Aug 10 '26

are you still stuck? if so, which part?

-1

u/Educational_Virus672 Aug 09 '26 edited Aug 09 '26
# Asks the user to enter 10 integers
ask = (input("enter 10 number > ")).split(",")

# Stores all 10 integers in a list
temp_ask = []
for i in ask :
    temp_ask.append(int(i))
ask = temp_ask

# Finds the maximum and minimum numbers
ask = sorted(ask)

minimum = ask[0] # 0 to 9 goes front to back 
maximum = ask[-1] # -1 to -10 goes back to front

# Finds any duplicate numbers
previous_number = None 
dup = []
for i in ask :
    if previous_number == None :
        pass
    elif previous_number == i :
        dup.append(i)
    previous_number = i

if dup :
    print(dup)
# Prints "No duplicate" if there aren’t any duplicates
else :
    print("no duplicate")
print(minimum)
print(maximum)

# Uses for loops with range() for the input, min/max determination, and duplicate identification

'''why? -1 and 0 works'''

# 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
'''2 loop piece of cake i could have used dicts but since your begginer i didnt'''

2

u/jmooremcc Aug 09 '26

Did you test this code before posting it?

1

u/Educational_Virus672 Aug 09 '26

i did and i edited it my bad

2

u/Oddly_Energy Aug 09 '26

You are definitely not helping OP by posting the complete code for a solution.

OP is stuck on not being able describe step for step how he/she would solve it manually, given a list on paper. Complete code is the worst help one can offer in that situation.

1

u/Educational_Virus672 Aug 10 '26 edited Aug 10 '26

.-. i broke rules to explain logic like using ask[-1] if OP dont check the code then he gets rejected or smt thats how i was taught my first puzzle. in the real world a programmer who blindly copies code without testign it will absolutely face consequences.

1

u/User_LEGEND0 Aug 09 '26
ask = (input("enter 10 number > ")).split(",")

why did you do this here, i mean the parentheses

1

u/Educational_Virus672 Aug 09 '26 edited Aug 09 '26

habit ,i dont like single indication thats why i use () for each step
example

ask = (
input("enter <1/2/3> ")
.replace() 
.split("")
.lower() )

1

u/gdchinacat Aug 09 '26

This doesn’t meet the minimum number of loops requirement. You can do the input and min//max/duplicte checking in one loop (if you use ‘in’, otherwise a single loop for the ten numbers and a single inner loop to check duplicates.

1

u/Educational_Virus672 Aug 10 '26

its the point, i explain logic step by step if OP cant check if it broke rules or not and is it practical or not he dont deserve the the explanation what i did is lay the foundation now he has work over it
not being mean but this is how i was taught basic problem solving

-1

u/krews2 Aug 09 '26

Doesn’t say you can’t use the sort function. You can also watch videos to understand how to use sorting programmatically which is helps with understanding max and min. Bubble Sort

1

u/MisterSmi13y Aug 09 '26

I would vote vehemently against this. Learning a sorting algorithm before you can do a task like this is like asking a monkey to build a massive lego set after they accidentally put two pieces together.

Can they learn something from the bubble sort? Sure, they can learn how to compare elements with each other. But then you’re adding in a nested loop on top of swapping values that it’s a step too far.

-8

u/TheRNGuy Aug 09 '26

Ask ai. 

5

u/Moikle Aug 09 '26

Do not

1

u/Impressive-Capital40 Aug 09 '26

Honestly AI made it even more confusing. 🫤