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.
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?
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!
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
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!
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!
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
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
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!
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.
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.
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.
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 !
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.
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
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.
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.
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.
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. 🥳
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.
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.
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.
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)
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.
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)
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.
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.
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.
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
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)
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!
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.
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}')
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)
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.
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.
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)
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?
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.
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.
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.
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]
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?
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 ")
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
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.
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
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)
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?
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.
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.
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 agreed, most programing tutorials on RUclips doesn't bother to giver the viewers homework which makes it feel unimportant to the viewers
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.
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.
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)
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 😋 🥃
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.
It becomes easier every time, practise does matter. Legend. numberGrades=int(input('How many grades do you have? ')) grades=[] for k in range(0,numberGrades,1): grade=float(input('Give me grade ')) grades.append(grade) sum=0 for k in range(0,numberGrades,1): sum = sum + grades[k]; average=(sum/numberGrades) print('You have an average of' ,average) print('Your grades are:') for k in range(0,numberGrades,1): print(grades[k]) highest=grades[0] for k in range(0,numberGrades,1): if (grades[k]>highest): highest=grades[k] print('Your highest grade is ', highest) lowest=grades[0] for k in range(0,numberGrades,1): if (grades[k]
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 ;-)
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.
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.
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
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]
I guess I'm a cheating legend. I just used Python's built in min(), max() '''maxGrade = max(grades) print('Your maximum grade is ', maxGrade)''" functions the first time through. I thought "Well,... this is incredibly easy. I must be doing something wrong." Sure enough, when I listened again to the end of lesson 9, you wanted us to use for loops. It took a lot longer but I got there eventually.
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.
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?
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!
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
That's a smart solution! I like that it uses the first input grade as the reference grade.
Great teacher, great character, great mind! God bless you!
sir, your lecture about python is better than any other lecture series even the paid course............
True indeed
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!
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!
I initially set lowGrade and highGrade to the first value of the grades list which also worked. Thank you Paul!!
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
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
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!
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!
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.
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.
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.
Two if statements for last week's homework! I'll go ahead and post my "I am legend!"
YOU ARE ONE OF MY MENTORS, A MAN OF GOD AND MAN OF KNOWLEGE. I SEE MY OLD SELF. GOD BLESS YOU SIR
And God bless you as well!
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 !
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.
This was what I settled on as well.
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.
Fantastic!
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
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.
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.
Love to see you teaching us C someday. Shout out for the Best teacher on youtube.
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.
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. 🥳
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.
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.
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.
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)
I AM LEGEND AGAIN! Small addition to previous homework. Thanks, Paul!
I tried and succeeded ... very nice lessons after the Arduino series ... thanx Paul!
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.
Excellent!
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)
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.
Keep it up
I am legend. My solution was similar to yours but I placed both if statements in a single for loop. Many thanks Mr. McWhorter
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.
Thank you so much!! I learn a lot and I very appreciate all your great videos
I'm so glad!
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.
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
As always, great lesson Sir
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)
LEGEND!
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!
Excellent!
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.
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
Got it! Struggled but got it! Thanks TTB!
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}')
Done by consolidating functions into two "for" loops, hence I AM LEGEND (all caps).
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)
I AM LEGEND! took me an hour and a half to solve it but I resisted the temptation to just google the answer
I did it a bit differently and a more roundabout way hahaha
I Am Legend!
Thank You Mr. Paul For Your Excellent Tutorials!
Glad you like them!
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.
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.
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)
Thank you for another great lesson, Sir! Your lessons are not wasted time (#NWT) ! 👍
Did not watch live, but I was Legend!
SIR LOVE FROM INDIA (U ARE soo dam great!!!)
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?
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.
@@paulmcwhorter Yeah. Thank you!
Love your lessons
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.
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.
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.
I am legend! Sadly I missed this live today!
Really having fun, rising the rank of I am Legend.
Yes you are!
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]
Paul the background screen saver - cool ! Can you provide a link to where I can down load it
The sort, max and min Python functions make things easier.
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?
I'm a 65 year Legend, thanks to you.
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
LEGEND!
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
")
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
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.
LEGEND!
Can we also use the min() and max() function instead of this for loop?
No, because you do not learn how to think and problem solve with that.
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
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)
Paul, I am LEGEND !
LEGEND!
I gave my level best. But I was not able to write the code myself. Thanks for teaching us
sir I actually used the max() and min() functions in my program. Is that fine with you?....It worked like a charm...
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?
@@paulmcwhorter sure sir I will think this through from next time
Thanks a lot for the advice sir!!.... I was able to do the sorting one myself without functions🎉🎉🎉🎉🎉
thank you , you are legend!
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)
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.
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.
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?
Really you want to think through it. It is a classic problem and will train your brain to think through such things.
@@paulmcwhorter agreed, most programing tutorials on RUclips doesn't bother to giver the viewers homework which makes it feel unimportant to the viewers
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.
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.
Legend again
LEGEND!
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)
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
I AM LEGEND and proud to be learning Python
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 😋 🥃
Excellent! If at first you do not succeed, try try again.
@@paulmcwhorter The problem is when I put in two grade that are the same as eachother, then it doesn't work properly 🙄 🤷 🤦
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.
It becomes easier every time, practise does matter. Legend.
numberGrades=int(input('How many grades do you have? '))
grades=[]
for k in range(0,numberGrades,1):
grade=float(input('Give me grade '))
grades.append(grade)
sum=0
for k in range(0,numberGrades,1):
sum = sum + grades[k];
average=(sum/numberGrades)
print('You have an average of' ,average)
print('Your grades are:')
for k in range(0,numberGrades,1):
print(grades[k])
highest=grades[0]
for k in range(0,numberGrades,1):
if (grades[k]>highest):
highest=grades[k]
print('Your highest grade is ', highest)
lowest=grades[0]
for k in range(0,numberGrades,1):
if (grades[k]
What if we don't have any idea about lowgrade, everything depends on the user input.. how can that be handled?
hello sir please the explain the concept ot Highgrades and lowgrades, because its very confusing.
i did it two ways haha one of the ways is the hw you've given us. bubble sort
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 ;-)
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.
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.
@@paulmcwhorter I 100% accept your point
If we use fewer for statements will that make the program faster ?
nailed it !
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
I am Legend this time round
Sir it's an grand request that please write an python code that converts pictures into string art and gives algorithm output please sir🙏🙏🙏🙏
I did it! I am legend!
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]
you are genius
Took a little bit, but I got it!
I guess I'm a cheating legend.
I just used Python's built in min(), max()
'''maxGrade = max(grades)
print('Your maximum grade is ', maxGrade)''"
functions the first time through. I thought "Well,... this is incredibly easy. I must be doing something wrong." Sure enough, when I listened again to the end of lesson 9, you wanted us to use for loops. It took a lot longer but I got there eventually.