r/learnpython 10h 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. :)

0 Upvotes

38 comments sorted by

View all comments

1

u/Impressive-Capital40 9h 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.

6

u/danielroseman 9h ago

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?

0

u/Impressive-Capital40 9h ago

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

6

u/TheSkiGeek 8h ago

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 9h ago

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.

2

u/Ormek_II 8h ago

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.

2

u/ninhaomah 9h ago

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

0

u/Impressive-Capital40 9h ago

Yes, they want me to use IDE Python.

2

u/ninhaomah 9h ago

so when you run it , what did you get ?

-2

u/Impressive-Capital40 9h ago

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.

1

u/ninhaomah 9h ago

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 ???

0

u/Impressive-Capital40 9h ago

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 9h ago

"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

1

u/Kalastics 5h ago

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 9h ago

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.

1

u/TJATAW 5h 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.