Python Tutorial 11: Finding Maximum and Minimum Numbers in a List in Python

  Рет қаралды 24,695

Paul McWhorter

Paul McWhorter

Күн бұрын

You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:
/ paulmcwhorter
In this video we show step-by-step instructions on how to write a python program that will find high and low numbers in a list. I do not assume you are an expert, so these lessons are designed for complete beginners.
#Python
#Lessons
#Programming

Пікірлер: 290
@mecatronicsforeveryone9565
@mecatronicsforeveryone9565 3 жыл бұрын
you literally changed my life. I just can't get enough of your classes. I started Arduino with you. and now python. I wish you the best, wherever you are and whatever you do.
@neilausten9404
@neilausten9404 3 жыл бұрын
Your teaching style makes it almost seem as though you are here, in my room, in person. Makes it easy to learn for folk of any age.(spoken by a 76 year old). Can I do a one off donation?
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
Thank you for the kind words. Donations can be made at my patron account, with a link above in the video description, or can be sent via paypal to paul.mcwhorter@gmail.com Thanks!
@petefontana1958
@petefontana1958 2 жыл бұрын
I am a 75 year old legend. My solution was to stored the first grade in the array as minimum grade in one for loop, and as the maximum grade for the other for loop.This way I can use this same function in any program to determine high and low. I started with your Arduino tutorial 18 months ago. You have kept my mind from turning into mush. Keep up the good work and God Bless
@426F6F
@426F6F 9 ай бұрын
That's a smart solution! I like that it uses the first input grade as the reference grade.
@iansesat6643
@iansesat6643 3 жыл бұрын
To the best online teacher, thank you for the content. You make us see the fun in doing engineering. It isn't always about the hard stuff, we can also do a lot of cool stuff
@sabbirahmad8326
@sabbirahmad8326 3 жыл бұрын
sir, your lecture about python is better than any other lecture series even the paid course............
@sunilkulkarni4426
@sunilkulkarni4426 3 жыл бұрын
True indeed
@426F6F
@426F6F 9 ай бұрын
I agree. Paul is not only a great teacher, but a fantastic engineer. He conveys complex information in such a simple, easy-to-grasp way for everyone. That's how you know he's so knowledgeable!
@TyroneJester
@TyroneJester 3 жыл бұрын
i am legend. Omg i was having so much trouble understanding loops but theses last couple of homeworks helped alot. i rewatched them over and over again untill it stuck. keep up the good work. you have a fan here in Ireland, great teaching method
@thisismyworkshop6654
@thisismyworkshop6654 3 жыл бұрын
Hey, Paul! The way I did the homework was - # max grade max=grades[0] for i in grades: if i > max: max=i print('Max grade is: ', max) #min grade min=grades[0] for i in grades: if i < min: min=i print('Min grade is: ', min) This way we are not stuck to 0-100 system, we might as well give negative grades. Is there a school somewhere in the world where teachers give negative grades, though? :) I love your tutorials and it's a pity, these tutorials are not used in high school programs all around the world.. Especially in this C19 era.. I can't wait to see the next ones. Wish you all the best!
@vaughntaylor2855
@vaughntaylor2855 3 жыл бұрын
I initially set lowGrade and highGrade to the first value of the grades list which also worked. Thank you Paul!!
@LiamAllbright
@LiamAllbright 8 ай бұрын
This course is legendary. you literally changed my life, and in some way, encouraged me to learn blender! Cant wait for more. 👍 Love these lessons!
@cbrombaugh
@cbrombaugh 3 жыл бұрын
I AM LEGEND AGAIN! Small addition to previous homework. Thanks, Paul!
@HonestDino
@HonestDino 15 күн бұрын
Great teacher, great character, great mind! God bless you!
@pauivorra1819
@pauivorra1819 3 жыл бұрын
As always, great lesson Sir
@opalprestonshirley1700
@opalprestonshirley1700 3 жыл бұрын
Finished the homework, made this old man's brain work overtime, but she'll sort with best of them. This just gets better and better. See you next week.
@leandersachin9666
@leandersachin9666 3 жыл бұрын
Love to see you teaching us C someday. Shout out for the Best teacher on youtube.
@johnmontesi383
@johnmontesi383 9 ай бұрын
Thank you for putting out these tutorials. I have been able to complete each of the homework assignments although I tended to complete them differently. Rather than keep creating loop statements I combined several operations into less loops. My thought is that the less coding you have to do... the less of a chance for error. Maybe this goes back to my programming years ago in languages that would seem foreign today. But your lessons definitely help with my understanding of the syntax of Python.
@codecage9333
@codecage9333 3 жыл бұрын
Two if statements for last week's homework! I'll go ahead and post my "I am legend!"
@bertmouthaan
@bertmouthaan 2 жыл бұрын
I tried and succeeded ... very nice lessons after the Arduino series ... thanx Paul!
@alfredcalleja450
@alfredcalleja450 Жыл бұрын
Hi Paul, thanks for another great tutorial. I worked it out on my own (with the help from your hints) but I had a lot of pain with my using == instead of =. Thanks for pressing home the value of doing it myself instead of just copying your code: I banged my head against the wall quite a bit. 🥳
@426F6F
@426F6F 9 ай бұрын
I ended up calculating the high grade, low grade, sum, and appending each grade to grades, as the user types them in - all within one for loop! Thanks Paul!
@lananhnguyen2925
@lananhnguyen2925 Жыл бұрын
Thank you so much!! I learn a lot and I very appreciate all your great videos
@paulmcwhorter
@paulmcwhorter Жыл бұрын
I'm so glad!
@jabber2824
@jabber2824 Ай бұрын
I am legend. You could also initialize the high and low value with the first number in the array. Then you wouldn’t have to know the scale of what you are going through. HighestGrade = grades[0]. Great lesson as usual! Thank you !
@charlielowell4077
@charlielowell4077 2 жыл бұрын
I AM LEGEND! I beat the lesson #10 homework with that folded up Walmart lawn chair like it was a cheap Walmart rug. It didn't take much tinkering. I guessed that there was a means of showing the min & max values of "something" so I experimented and got it right pretty quickly. Thanks again for the retiree brain food! By the way, I have done the last two homeworks with only two "for's"???? It works.
@hmccall3
@hmccall3 Жыл бұрын
Thanks for another great lesson Paul! I made sure I could do it by using for loops, then I re-wrote the code and cheated by using the min(array) and max(array) functions. I think it's important to learn all the ways to skin a cat! LOL
@ecassar1975
@ecassar1975 3 жыл бұрын
I am legend. My solution was similar to yours but I placed both if statements in a single for loop. Many thanks Mr. McWhorter
@hughpatterson1480
@hughpatterson1480 2 жыл бұрын
Great lesson Paul! While I was able to create the homework problem, I had a problem with the average adding up the grades entered rather than averaging them. It ended up being a rookie mistake. However, you learn more from making mistakes that getting things right the first time!
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Excellent!
@lemonlover5011
@lemonlover5011 Жыл бұрын
Love your lessons
@irete267
@irete267 Жыл бұрын
I am a legend. I used the very first element in the list as both the low grade and the high grade. Seems it works either ways:) Been enjoying your lessons btw keep up the good work sir.
@paulmcwhorter
@paulmcwhorter Жыл бұрын
Excellent!
@saptangshumanna9919
@saptangshumanna9919 2 жыл бұрын
In my solution instead of setting lowgrade and highgrade as 100 and 0 respectively, I defined both of them to be equal to grades[0]. I did it in case the user has grades more than 100. And this would help to find the min and max for any value of the array.
@ModernDayWanderlust
@ModernDayWanderlust 2 жыл бұрын
This was what I settled on as well.
@nyrootu9954
@nyrootu9954 3 жыл бұрын
YOU ARE ONE OF MY MENTORS, A MAN OF GOD AND MAN OF KNOWLEGE. I SEE MY OLD SELF. GOD BLESS YOU SIR
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
And God bless you as well!
@go-ek7sg
@go-ek7sg 3 ай бұрын
I am Legend! I folded up like a lawn chair on the last homework but got this one. Thank you so much for these lessons.
@paulmcwhorter
@paulmcwhorter 3 ай бұрын
Fantastic!
@86Carrera911
@86Carrera911 2 жыл бұрын
I am LEGEND! I did the low and high grade checking in the same loop, and initialized both of the values to grades[0]. As the size of the data set increases, your execution time will increase at a lower rate.
@charlielowell4077
@charlielowell4077 2 жыл бұрын
After thinking about it, I realized I used Python's built in functions for min & max. While that worked and worked very well I saw that, since other programming languages probably don't have the same built in's that Python 3 has, I needed to redo my homework. That said, I owe you an apology as I did both you and myself a disservice. I managed to redo the min & max homework "old school" style, but had a lot of difficulty. I finally got it to where it works but i still don't think I got it done the way I was supposed to. I'm going to go through #11 again so I can see where i can improve my code. I need to do the same for lesson #12, as the sort("list") function is also probably not the best way to do it. Certainly the easiest, but not the best. Thanks again, sir.
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Yes, the point of the lesson is to get you to think through the complicated problem. Map out a strategy, and then code it. Using the built in functions you really dont learn anything and really dont build brain power.
@bryankohn9660
@bryankohn9660 3 жыл бұрын
I am legend. Got this via two methods. A for loop that steps thru and compares each grade, and also used a Python list methods .min and .max. This revealed that there are many many many list methods in Python.
@chrisb7250
@chrisb7250 9 ай бұрын
I wrote a python program with a conditional statement that turns a pump "On" when the depth in a tank reaches a specific "Minimum depth" and shuts the pump off when it reaches a specified "Maximum depth". I am excited to put this into practice with my arduino.
@professorxavier9692
@professorxavier9692 2 жыл бұрын
I folded up like a cheap Walmart lawn chair but spent 3 hours experimenting with all of the things you can do with loops and integers and had so much fun haha! I feel like struggling, even if you eventually don't find the solution is important for sure.
@MrElFRanz
@MrElFRanz 3 жыл бұрын
Hello Paul; Today I finished the homework of this lesson, and I did not use the sort function. It took me many hours. I am 78 years old, and your homework keep my brain from rusting.
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
Keep it up
@danielbanks7500
@danielbanks7500 3 жыл бұрын
I am legend! Sadly I missed this live today!
@dzeykop
@dzeykop Жыл бұрын
Thank you for another great lesson, Sir! Your lessons are not wasted time (#NWT) ! 👍
@jg1950mc
@jg1950mc 3 жыл бұрын
Great teaching! my code with one for loop for all calculations and one for loop for printing ''' average the grades and print average and all grades given find the highest and lowest grades entered ''' grades = [] total = 0 high = 0 low = 100 num1 = int(input('How many grades will you enter? ')) for grade in range(num1): grade = int(input('Enter a grade: ')) if grade > high: high = grade if grade < low: low = grade grades.append(grade) total = total + grade print('you entered: ', end = ' ') for g in range(0, num1, 1): print(grades[g],end = ', ') print('The average grade is:', total / num1) print('The highest grade is', high, 'and the lowest grade is', low)
@JackVersey
@JackVersey 3 ай бұрын
Going to declare myself super legend here. Only used 2 for loops, 19lines of code in total. I particularly like the simplicity of lines 7-14 which ensures the first entry is always both the highest and lowest grade and takes care of it from then on (also any real value of grades can be used here... gradesnum = int(input('How many grades are there? ')) grades, total, highest, lowest = [], 0, 0, 0 for i in range(0, gradesnum): grade = float(input('what is grade number ' + str(i + 1) + '? ')) grades.append(grade) total = total + grade if(i == 0): highest = grade lowest = grade else: if(grade > highest): highest = grade if(grade < lowest): lowest = grade print('The grades are as follows:') for i in range(0, gradesnum): print('Grade' + str(i + 1) + ':', grades[i]) print('The average of the grade is', total/gradesnum) print('The highest grade was', highest, 'and the lowest grade was', lowest)
@paulmcwhorter
@paulmcwhorter 3 ай бұрын
LEGEND!
@TheSudouser
@TheSudouser 2 жыл бұрын
Got it! Struggled but got it! Thanks TTB!
@FernandoMartinez-kw9kj
@FernandoMartinez-kw9kj 2 жыл бұрын
Figured it out :) I miss the Arduino IDE where all the variables are declared from the start and you know what you’re working with. I hope i will recognize the benefits of python later on, for now it gives me headaches haha
@geoffwade8144
@geoffwade8144 2 жыл бұрын
I am legend, I suppose.... I only used 1 for loop and did all of the calculations in the same loop. Much different from Pauls' solution, kind of missed the point of where Paul is leading us I think, but I get it now.
@drorlivneh4499
@drorlivneh4499 2 жыл бұрын
thank you , you are legend!
@MuhammadHamza-ki3ze
@MuhammadHamza-ki3ze 3 жыл бұрын
I stored first element of grades as minimum grade in one loop, and maximum grade for the other loop and it works perfectly I am a Legend
@Hyrkan24
@Hyrkan24 Жыл бұрын
I AM LEGEND! took me an hour and a half to solve it but I resisted the temptation to just google the answer
@Hyrkan24
@Hyrkan24 Жыл бұрын
I did it a bit differently and a more roundabout way hahaha
@chrisb7250
@chrisb7250 9 ай бұрын
I found a couple of different methods of completing this assignment. The first way was to use the max and min functions in python. The second way was using a for loop, and first assuming min is equal to grades array position [0]. Then as it would iterate through grades it would check each position, and if it was less than min, that would become the new min. min = grades[0] for i in grades: if (i < min): min = i print('Min:', min)
@SimpleHumanInNY
@SimpleHumanInNY 2 жыл бұрын
I have learnt something new today, thank you for the video. I must say I cheated a bit with the solution, I apologize to Mr. McWhorter and the community. I used the sort function on the array and then just pulled and displayed the first element (at index 0) and the last element (at index -1) in the list of grades.
@yveslagace8212
@yveslagace8212 2 жыл бұрын
Paul, I am LEGEND !
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
LEGEND!
@hassanniaz7583
@hassanniaz7583 3 жыл бұрын
Here's how I did it: x=[] question=int(input('How many grades do you want to enter: ')) questions=question+1 for ques in range(1,questions,1): y=float(input('Enter your Grade ')) x.append(y) num=1 for grades in x: print('Your grade#',num,'is: ',grades) num=num+1 sum=0 max=x[0] min=x[0] for grades in x: sum=sum+grades if(max=grades): min=grades print('The average of given grades is =',sum/question) print('Your maximum grade is:',max) print('Your minimum grade is:',min)
@arnaudmasse7839
@arnaudmasse7839 2 жыл бұрын
nailed it !
@danielduplessis7221
@danielduplessis7221 2 жыл бұрын
I Am Legend! Thank You Mr. Paul For Your Excellent Tutorials!
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Glad you like them!
@williamhyrkas698
@williamhyrkas698 2 жыл бұрын
Legend again
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
LEGEND!
@nielsroetert
@nielsroetert 3 жыл бұрын
Have you looked at using formatted string literals at all, they were introduced in Python 3.6 and make your code look so much nicer. From my homework: print(f'Your average grade is {average}, your lowest grade is {low_grade} and your highest grade is {high_grade}')
@martinc9215
@martinc9215 Жыл бұрын
Almost a legend, I tried only to compare values within the array without reference to any external datum. As a result I had trouble comparing the first or last entry in the array. I ended up with index ranging errors. So I compared the first and last elements outside of the comparison 'for loop' and used one of them as the lowest value for the remaining pairwise comparisons within the loop. This works and I suppose I'm a bit of a legend because my code can find the highest and lowest values in an array of any number values. 😎
@ICit123
@ICit123 3 жыл бұрын
I kept the original program and added this python line at the end of the program: print("Maximum grade is :", max(grades), " Minimum grade is :", min(grades)) It works with no FOR LOOP necessary.
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
But the object of the lesson is to think through a complex problem analytically, and then design a solution and code it. Simply using someone else's canned function, you do not learn how to think through the problem. These min, max, average and sort problems are classic coding problems, and people need to know how to solve them.
@ShinesMonkey1
@ShinesMonkey1 3 жыл бұрын
Did not watch live, but I was Legend!
@sailingskismo
@sailingskismo 6 ай бұрын
Well, I did some interweb research and found two python keywords (min & max) so I just used two lines to determine the lowest and highest values results.append(result) maxGrade=max(results) minGrade=min(results) print('and your lowest grade was', minGrade , 'while your highest grade was' , maxGrade) Having tested it, it works ok.
@boydrogers7227
@boydrogers7227 3 жыл бұрын
Done by consolidating functions into two "for" loops, hence I AM LEGEND (all caps).
@mannatkaur1146
@mannatkaur1146 3 жыл бұрын
Hi Paul, I wanted to ask something. You said that we have to use a for loop in order to sort the numbers in the list. I did it by using the 'sorted()' function command. Is that right or it would be better to find it using a for loop?
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
What do you learn by using a canned function . . . noting. You have not learned to analyze a hard problem and then develop and implement an algorithm to solve. That is what you need to learn how to do, as that is what people will pay for.
@mannatkaur1146
@mannatkaur1146 3 жыл бұрын
@@paulmcwhorter Yeah. Thank you!
@Azekanawesom
@Azekanawesom 2 ай бұрын
hey paul,love your teaching and ur efforts. Absolutely phenomenal.Heres my code(slightly different than urs): n=int(input('Enter the no. of grades:')) grades=[] sum=0 for i in range(0,n,1): grade=int(input('Enter your grade:')) grades.append(grade) sum=sum+grade for j in range(0,n-1,1): if(grades[j]grades[j+1]): max= grades[j] min=grades[j+1] avg=sum/n print('ur grades are:') print(grades) print('ur average grade is:',avg) print('ur maximum grade is:',max) print('ur minimum grade is:',min)
@blasterTC
@blasterTC 3 жыл бұрын
My solution was to first start with biggest grade and then, when searching for smallest, make the initial variable same as the biggest so i know it cannot get lower than low.
@advancedperformance9721
@advancedperformance9721 3 жыл бұрын
thank u sir
@praneethreddy6947
@praneethreddy6947 3 жыл бұрын
SIR LOVE FROM INDIA (U ARE soo dam great!!!)
@jeff_wild
@jeff_wild 29 күн бұрын
I am legend. I tracked high and low scores while adding to the array, so no new for statements needed. Initially set high to zero and low to 100.1
@paulmcwhorter
@paulmcwhorter 28 күн бұрын
LEGEND!
@pasteltiara
@pasteltiara 3 жыл бұрын
Really having fun, rising the rank of I am Legend.
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
Yes you are!
@Al-dp1pe
@Al-dp1pe 2 жыл бұрын
Paul the background screen saver - cool ! Can you provide a link to where I can down load it
@whimsicalkins5585
@whimsicalkins5585 2 жыл бұрын
I gave my level best. But I was not able to write the code myself. Thanks for teaching us
@Ameer5CT
@Ameer5CT 2 жыл бұрын
If we use fewer for statements will that make the program faster ?
@mrelectronrock9510
@mrelectronrock9510 3 жыл бұрын
you are genius
@jimsimpson1006
@jimsimpson1006 7 ай бұрын
I am legend. Well, getting there bit by bit… Again, Paul, you’ll be glad to know I was shouting at you to initialise, but as you’re in Texas and I’m in Ireland you probably didn’t hear me.
@paulmcwhorter
@paulmcwhorter 7 ай бұрын
LEGEND!
@wendygrant2735
@wendygrant2735 2 жыл бұрын
Jetfuel, not soda-pops, not coca-cola's, not mountain dews. In my country we have an ad that says 'Red Bull gives you wings'. Mr McWhorter maybe drinking this is the solution to fly the jet.
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Ah Red Bull will probably kill you quicker than any of the others. Amazing to me living in a remote part of Africa, the syrupy drink pushers are already here trying to get folks to spend their hard earned money on sugary drinks.
@adirajchalotra4916
@adirajchalotra4916 Жыл бұрын
I did it! I am legend!
@ModernDayWanderlust
@ModernDayWanderlust 2 жыл бұрын
Took me a bit of playing around before I was happy with this one, I was trying to get too cute with it and do everything in a single loop. I defined both highGrade and lowGrade to gradeValues[0] initially so that any funky grades (over 100, etc) would still read correctly.
@michelspedding2032
@michelspedding2032 Жыл бұрын
I'm a 65 year Legend, thanks to you.
@mannatkaur1146
@mannatkaur1146 3 жыл бұрын
Can we also use the min() and max() function instead of this for loop?
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
No, because you do not learn how to think and problem solve with that.
@littricks3631
@littricks3631 3 жыл бұрын
I wanted to use them bro,cause I thought there's no restriction on what the user can type(here he's typing marks so it has to be any number within the range 1-100)...but say the guy typed 32767,that value won't be read by this program and we would require the functions you mentioned! You're good to use it if you thought like I did
@catheria-clairebara9202
@catheria-clairebara9202 10 ай бұрын
What if we don't have any idea about lowgrade, everything depends on the user input.. how can that be handled?
@kalpeshpawar2201
@kalpeshpawar2201 3 жыл бұрын
Sir it's an grand request that please write an python code that converts pictures into string art and gives algorithm output please sir🙏🙏🙏🙏
@thekanwalchaudhari5225
@thekanwalchaudhari5225 Жыл бұрын
Sir to find maximum we can use the function max(). And for minimum we can use min(). So in this case it will be max(grades) and min(grades)
@paulmcwhorter
@paulmcwhorter Жыл бұрын
The whole point of the lesson was for you to think through the problem, and solve a difficult challenge by careful analysis and critical thinking, not just use a canned library, so no, dont use the functions figure out the logic and write the code.
@criptosauro4587
@criptosauro4587 Жыл бұрын
I did the same solution. another way I thought was to set : high_grade = grades[0] low_grade = grades[0] but this way have to write after the first for loop cause at the beginning grades[0] is empty here is the rest: # Ask the amount of grades amount = int(input("How many grades do you have? ")) grades = [] total = 0 high_grade = 0 low_grade = 100 # write all grades in the grades[] for i in range(0,amount,1): grade = float(input("Please share your grade ")) grades.append(grade) # Calculate the average (2 different ways) average = sum(grades) / amount for i in range(0, amount, 1): total = total + grades[i] average_2 = total/ amount # MAYOR for i in range(0, amount, 1): if grades[i]>= high_grade: high_grade=grades[i] # Menor for i in range(0, amount, 1): if grades[i]
@narlyb1500
@narlyb1500 Жыл бұрын
I used IF statements in the first for loop: """ 1) ask the user for how many grades they have. 2) input those into an array. 3) average the grades 4) print out the average 5) print out all the grades 6) print out the highest and lowest grades ------------------------------------------------------------------------------ """ grades=[] number_grades=int(input('How many grades do you have? :')) high_number=float(0) low_number=float(0) for i in range(number_grades): grade=float(input(f'What is grade #{i+1} :')) if high_number==0: high_number=grade low_number=grade if grade>high_number: high_number=grade if grade
@colefisch931
@colefisch931 Жыл бұрын
I did lowGrade=grades[0] to make the first grade in the list default as the low and then check against it. that also worked for me.
@lananhnguyen2925
@lananhnguyen2925 Жыл бұрын
Hi cole, yes I also do the same. I actually think this could be more accurate. For example, if we are not talking about grades but an array of random numbers, if all the inputs are more than 100, the it will show 100 as the minimum which is incorrect. But doing your way, no matter how large the number is, it always turns out the correct minimum.
@MrElFRanz
@MrElFRanz 3 жыл бұрын
The sort, max and min Python functions make things easier.
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
The goal is not the easy solution, the goal is to learn to think through a problem and implement a solution. Using canned funcitons, what have you really learned?
@vandanasrivastava2028
@vandanasrivastava2028 3 жыл бұрын
I am legend. I did that a bit differently by not adding 2 more for loops instead I added the 2 if statements in the first for loop
@bhuvansk6770
@bhuvansk6770 Ай бұрын
ahh sir i still initialized both max= 0 and min = 0 and got the same output ? so is tat wrong or right i just wanted to know , program worked the same but i got the output correct itself like the lowgrade and highgrade were shown correct after initializing them both as 0 x = int(input('How many grade do you need : ')) z = [] min= 0 max =0 s= 0 max = 0 for i in range(0,x,1): y = int(input('Enter the grade : ')) z.append(y) s = s+z[i] min = z[0] avg = s/x print('Your ',x,' grades are : ') for i in range(0,x,1): print(z[i]) print('Average of your grades = ',avg) for i in range(0,x,1): if(z[i] < min): min = z[i] if(z[i]>max): max = z[i] print('Your lowest grade = ',min) print('Your highest grade = ',max)
@jstro-hobbytech
@jstro-hobbytech 2 жыл бұрын
i did it two ways haha one of the ways is the hw you've given us. bubble sort
@timothyj1962
@timothyj1962 3 жыл бұрын
I stopped in the middle to figure this one out. Seems one issue. We cannot assume that the highest grade would be 100. What if were based on 200? We can't up and rewrite the code every time the test has different scoring method. So we need to sort it out with the known variables. My method was to assume "lowScore=grades[0]" as a starting point. I placed that under the line of grades.append(grade). Then code "if (grades[i]
@mikekeller7342
@mikekeller7342 3 жыл бұрын
Took a little bit, but I got it!
@leprechaun947
@leprechaun947 2 жыл бұрын
Thank you for these excellent lessons! Here's my solution to exercise 9/10: # Grades program by leprechaun947 # Guided by Paul Mc Whorter and fuelled by strong coffee # Define array to hold grades grades = [] # collect grades and populate the array numGrades = int(input("Please enter the number of grades: ")) for i in range(numGrades): grade = int(input("Please enter grade: ")) grades.append(grade) print(" Your grades are:") # Print out list of grades for grade in grades: print(grade) # Calculate average grade sum = 0 for grade in grades: sum += grade average = sum/numGrades print("The average grade is: ", average) # Find the highest grade. high = grades[0] for grade in grades: if grade > high: high = grade print("The highest grade is", high) # Find the lowest grade. low = grades[0] for grade in grades: if grade < low: low = grade print("The lowest grade is", low) print(" Done - thank you ")
@polito-yd8fp
@polito-yd8fp 11 ай бұрын
I am Legend this time round
@ottawakravmagaacademy7013
@ottawakravmagaacademy7013 3 жыл бұрын
I AM LEGEND and proud to be learning Python
@trondnilsen4542
@trondnilsen4542 Жыл бұрын
My fault solution based on that Average already found did not work for if all grades are same(average). Had to struggle through many versions before i realized differece between range- and array-metode. So thanks to Paul for giving me the correct solution. NOT PERFECT: ... highest=0 lowest=100 for grade in grades: print('Innhold(karakter) : ', (grade)) #To track the iterations if (grade > Average and highest grade): lowest=grade print ('Din høyeste karakter : ', highest) print ('Din laveste karakter : ', lowest)
@chernoblyat1901
@chernoblyat1901 3 жыл бұрын
I've done some deep research through Google on how to find smallest and highest numbers in arrays. The easiest way I found was to use the command "min" for smallest number and "max" for highest number on my own! Does this count as individual hard work or did I fold it up like a cheap Walmart lawn chair?
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
Really you want to think through it. It is a classic problem and will train your brain to think through such things.
@chernoblyat1901
@chernoblyat1901 3 жыл бұрын
@@paulmcwhorter agreed, most programing tutorials on KZbin doesn't bother to giver the viewers homework which makes it feel unimportant to the viewers
@yasararif8292
@yasararif8292 2 жыл бұрын
What happens if you wrote a grade giver than 100. Wouldn’t you need to stop the user making that mistake or prompting him to try a valid input. Regards
@jdb222
@jdb222 3 жыл бұрын
Hello, the problem should disappear after saving the change..... observe the 'Explorer' icon (l/h upper corner of the VSC window)...but I also still do not know all the settings of VSC ;-)
@bigbogeyface
@bigbogeyface 3 жыл бұрын
I spent nearly 3 hours trying to do this homework and folding up like a cheap garden deckchair 😔 Then, after a few days, I decided to try again 🤨 And, well, I'm not going to give the game array 🤭 I mean away!!! 🤦🤦🤦🤫 But I'm now sitting back in my deckchair like a legend 😁 drinking a nice glass of ice tea 😋 🥃
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
Excellent! If at first you do not succeed, try try again.
@bigbogeyface
@bigbogeyface 3 жыл бұрын
@@paulmcwhorter The problem is when I put in two grade that are the same as eachother, then it doesn't work properly 🙄 🤷 🤦
@raavn0007
@raavn0007 Жыл бұрын
hello sir please the explain the concept ot Highgrades and lowgrades, because its very confusing.
@lakshmadaan8871
@lakshmadaan8871 2 жыл бұрын
sir I actually used the max() and min() functions in my program. Is that fine with you?....It worked like a charm...
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Well, it is a little like getting someone else to write your code for you. You need to think through this and do it on your own. What will you do when you get to a harder problem where there is not a canned library?
@lakshmadaan8871
@lakshmadaan8871 2 жыл бұрын
@@paulmcwhorter sure sir I will think this through from next time
@lakshmadaan8871
@lakshmadaan8871 2 жыл бұрын
Thanks a lot for the advice sir!!.... I was able to do the sorting one myself without functions🎉🎉🎉🎉🎉
@Vbeck56
@Vbeck56 2 жыл бұрын
I am LEGEND but I used min and max feature..... in my print statement. I just started typing and saw a min feature so i started to play with it. print('Highest Grade is: ',max(grades)) print('Lowest Grade is: ',min(grades)) but I added the for loop/if statement in because its import to learn more ways of doing the same thing.
@daveflatters4981
@daveflatters4981 3 жыл бұрын
I have manually done the highest/lowest and sorted the list. I don’t see the sense in doing like this though. There is a Max, Min and Sort function built into lists and arrays. These are probably more efficient and less prone to errors.
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
We can learn to think for ourselves, or we can offload the thinking to others using their functions. I am trying to teach people to think for themselves, as problem solvers are the ones who find the large salaries. For those interested, I am trying to teach how to logically work through a hard problem.
@whimsicalkins5585
@whimsicalkins5585 2 жыл бұрын
@@paulmcwhorter I 100% accept your point
Python Tutorial 12: Simple Python Sorting Program
27:00
Paul McWhorter
Рет қаралды 24 М.
Python Tutorial 10: Homework Solution for Averaging Numbers
20:41
Paul McWhorter
Рет қаралды 23 М.
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 265 М.
Python Tutorial 18: Understanding Python Methods and Classes
42:43
Paul McWhorter
Рет қаралды 24 М.
The Fastest Way to Loop in Python - An Unfortunate Truth
8:06
mCoding
Рет қаралды 1,4 МЛН
Python Tutorial 17: Python Functions Examples and Solutions
27:45
Paul McWhorter
Рет қаралды 15 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,7 МЛН
Modern Python logging
21:32
mCoding
Рет қаралды 169 М.
6 Tips to write BETTER For Loops in Python
9:19
Patrick Loeber
Рет қаралды 247 М.
Tag him😳💕 #miniphone #iphone #samsung #smartphone #fy
0:11
Pockify™
Рет қаралды 4,5 МЛН
iPhone socket cleaning #Fixit
0:30
Tamar DB (mt)
Рет қаралды 18 МЛН
تجربة أغرب توصيلة شحن ضد القطع تماما
0:56
صدام العزي
Рет қаралды 64 МЛН
Vision Pro наконец-то доработали! Но не Apple!
0:40
ÉЖИ АКСЁНОВ
Рет қаралды 453 М.