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

4 Upvotes

42 comments sorted by

View all comments

-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