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

preview_player
Показать описание
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:

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
Рекомендации по теме
Комментарии
Автор

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.

mecatronicsforeveryone
Автор

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?

neilausten
Автор

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

petefontana
Автор

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):
max=grades
if(min>=grades):
min=grades
print('The average of given grades is =', sum/question)
print('Your maximum grade is:', max)
print('Your minimum grade is:', min)

hassanniaz
Автор

Great teacher, great character, great mind! God bless you!

HonestDino
Автор

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!

thisismyworkshop
Автор

I initially set lowGrade and highGrade to the first value of the grades list which also worked. Thank you Paul!!

vaughntaylor
Автор

sir, your lecture about python is better than any other lecture series even the paid

sabbirahmad
Автор

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

iansesat
Автор

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!

FF
Автор

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!

AxionRenParkston
Автор

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

TyroneJester
Автор

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.

chrisb
Автор

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.

johnmontesi
Автор

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.

charlielowell
Автор

im a legend (its been a while since thta video is out but paul i just wnated to tell you you realy help me at anything i ever wanted to know (programing, arduino, 3d designing, 3d printing and ai will come) big thanks to you i am broke rn but if i ever have money you will recieve some thank you )

leventkaya
Автор

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.

opalprestonshirley
Автор

Actually it only took my minutes to write it. If we are going to find the highest grade we gotta compare numbers. And the way we compare numbers, as we learned so far, is if statements with conditionals signs, ">" and "<". Here is my solution:

numGrades=int(input('How many grades do you have?: '))
grades=[]
for x in range(0, numGrades, 1):
grade=float(input('What is your '+str(x+1)+'. grade?: '))
grades.append(grade)
sum=0
for x in range(0, numGrades, 1):
sum=sum+grades[x]
average=sum/numGrades
print('')
print('Your grades are: ')
for eachGrade in grades:
print(eachGrade)
print('')
print('Your average grade is: '+str(average))
print('')
highest=0
lowest=grades[0]
for eachGrade in grades:
if(eachGrade>highest):
highest=eachGrade
if(eachGrade<lowest):
lowest=eachGrade
print('Your highest grade is: '+str(highest))
print('Your lowest grade is: '+str(lowest))

arslan
Автор

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 !

jabber
Автор

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)

chrisb