Python Tutorial 15: Solution to Python Pickle Homework Example Problems

  Рет қаралды 16,269

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 work some example problems in python using Pickle. I do not assume you are an expert, so these lessons are designed for complete beginners.
#Python
#Lessons
#Programming

Пікірлер: 231
@directhubfeexam
@directhubfeexam 3 жыл бұрын
Loved this lesson! I folded up like a cheap walmart chair (at least not a dollar general one) but this helped a lot! Thanks Paul.
@bola5671
@bola5671 Ай бұрын
Haha, that was kinda funny
@proteopathy
@proteopathy 2 жыл бұрын
I AM LEGEND. I made two separate programs. One to write the student data, the second to read and ask the user input. All of it was made to be non case-sensitive, with a clean layout. Love the realistic challenges you present. Very much a similar challenge to an intro to programming class one would encounter in college!
@cbrombaugh
@cbrombaugh 3 жыл бұрын
Your 78 year-old student is Legend! Keep up the great work Paul!
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
Thanks! Will do!
@aungphyokyaw4475
@aungphyokyaw4475 8 күн бұрын
I did the homework! I am finally a legend. Sometimes I cannot do the homework 100%, I always try to do my best, and suffer. Thanks for pushing us.
@jnecece
@jnecece 3 жыл бұрын
As always, I love your tutorials. Thank you.
@ModernDayWanderlust
@ModernDayWanderlust 2 жыл бұрын
Legend. I'm starting to feel confident enough to add in some loops for things like re-prompting for the number of students if the inputted number is 0 or less than zero, prompting to display the student roster before recalling a student, and similar types of small improvements. I know there's a TON of ways I can optimize the code I'm writing, but I feel like each program I write is getting better, which is a really awesome feeling! As always, thanks Paul!
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
LEGEND!
@ModernDayWanderlust
@ModernDayWanderlust 2 жыл бұрын
@@paulmcwhorter I want to add that some Googling brought me to str.upper, str.lower, and str.casefold... super helpful to eliminate list recall errors caused by string punctuation!
@jeantorres3293
@jeantorres3293 3 жыл бұрын
I am legend, I took python last year (currently a Junior in College) but I am amazed at how much you cover in such short time and with such clarity! Just have to strengthen my fundamentals with you
@silver5970
@silver5970 3 жыл бұрын
That was cool homework, i enjoyed doing it. It wasn't easy but it was doable! Love your work!
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
Great job!
@nicholastan8478
@nicholastan8478 2 жыл бұрын
I am legend. This took a while for me as i put everything into one list before dumping. happy to see different solutions
@potatoz1137
@potatoz1137 2 жыл бұрын
I am a LEGEND PAUL. I was so close to giving up but i wanted to be able to call myself a legend after being a lawn chair for so long so i kept thinking about it and reviewing our past assignments until it finally came to me like a bolt of lightning what to do :D. And now i am proud to say i have become a legend once again
@wendygrant2735
@wendygrant2735 2 жыл бұрын
This was fun indeed. Learnt a lot again. Thank you, Sir.
@opalprestonshirley1700
@opalprestonshirley1700 3 жыл бұрын
Mine was a bit different but yours was a bit simpler. Great job Paul.
@DeNihongoAsobou
@DeNihongoAsobou 3 жыл бұрын
It took time,but I did my homework!So fun.Thanks Paul
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
Wonderful!
@raymondwood3603
@raymondwood3603 7 ай бұрын
First lesson in Python Tutorial where you've asked us to hold our breath. My kids and I have been waiting for it.
@DrJALAGHARI
@DrJALAGHARI 3 жыл бұрын
Thank you so much for sharing this valuable information through this amazing video.
@gediminasgresevicius2901
@gediminasgresevicius2901 Жыл бұрын
This time i made it! So good feeling. I made it in one program, and then split them in two. It works :)
@rajeev01in
@rajeev01in 9 ай бұрын
Very good Paul. I am sixty five years old without any prior coding experience. Found your way of teaching excellent. This particular exercise was tough to me. But i tried my best and could make the first part 'somewhat' a success; though i know that there is no 'somewhat' in this field. Thank you.
@soundarrajankannan7692
@soundarrajankannan7692 3 жыл бұрын
I did my homework and solved it too.All thanks to you.
@0Mr.Java0
@0Mr.Java0 Жыл бұрын
I am legend! As always your lessons are great Paul! You are my go to for programing. I started with your Arduino lessons and got hooked! Can't wait to get you your Visual Python 3d Graphics and Animation.
@paulmcwhorter
@paulmcwhorter Жыл бұрын
Fantastic!
@426F6F
@426F6F 8 ай бұрын
I AM LEGEND!!! I was honestly a bit surprised when mine worked the first time around. Thanks, Paul, for all you do for everyone! You're the true legend, sir! I knew the receiver program would be the toughest part, and it took me about an hour or two to think through. I made an array called 'students' which stores the number of students as the first data type, the names as the second, and the grades as the final one. As the user inputs them and they are appended, the index of the individual 'grade' within 'grades' lines up with the index of the individual 'name' within 'names'. So I made a for loop to cycle through each name in the names array until it finds the string equal to the input name. Then, if the name is found, it uses that index for the same index as the grade. The program then prints out the student's name with the grade. It made it really easy!
@426F6F
@426F6F 8 ай бұрын
Here's my code! import pickle i=0 student=[] ans="Y" with open (c:/filePath/pickledStudentData.pkl','rb') as f2: student=pickle.load(f2) #print(student) #example [3, ['Paul', 'Karina', 'Vagan'], [100.0, 98.0, 65]] n=student[i] #print(n) #example: 3 names=student[i+1] #print(names) #example: ['Paul', 'Karina', 'Vagan'] grades=student[i+2] #print(grades) #example: [100.0, 98.0, 65] print(f"List of students: {names}") while(ans == "Y" or ans == "y"): namecall=input("Whose grade would you like to see? ") for i in range(0,n,1): if names[i] == namecall: grade = grades[i] print(f"{namecall}'s grade is {grade}") print("") ans = input("Would you like to see another grade? (Y/N): ")
@paulmcwhorter
@paulmcwhorter 8 ай бұрын
LEGEND!
@benthompson6118
@benthompson6118 Жыл бұрын
Great lesson Paul. In working through the homework I wanted to be able to leave myself notes in the program to come back to in the future and learned about the "#" to leave comments on lines. I think it would be awesome to mention that in the first few lessons so people can leave themselves notes.
@hughpatterson1480
@hughpatterson1480 2 жыл бұрын
Another great lesson Paul. I've been able to do the homework thus far. While I would say "I am Legend," I did study this when I went back to school to get a degree in IOT design and prototyping (just so I could build SDR ham radios and teach). It also took me a few tries....Thank for another great lesson! I will pass this on to my students!
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Excellent!
@sherlocksrobot1455
@sherlocksrobot1455 Жыл бұрын
I did it! That was a fun challenge. I decided to pickle a 2D array, but then I had to look into how to reference it. It wasn't until you passed the array size that I realized how useful that can be for error checking. I'm used to using rectangular datasets, so the ability to pass a single integer at the top is stretching my brain.
@davidschnider1297
@davidschnider1297 Жыл бұрын
thanks, Paul .. looking forward to Functions, Methods and Classes... yes having FUN... blessing so you...
@paulmcwhorter
@paulmcwhorter Жыл бұрын
Have fun!
@brandendowning1714
@brandendowning1714 11 ай бұрын
Legend! Thanks Paul! This was a fun one!
@jbelmont72
@jbelmont72 Жыл бұрын
I combined both programs into one with a combination of if /elif and input options. appended a data set and made the counter into a string which became the student ID. Thus could locate the student by student ID or any of the elements in each "appended "list. Really enjoyed this.
@jonathanlanders9406
@jonathanlanders9406 Жыл бұрын
I AM LEGEND! I was unsure about where to go for this one, but I took several educated guesses and managed to get it right the first time (ignoring some minor syntax issues). I did it differently than Mr.McWhorter. Instead of making two arrays (one for the students and one for the grades) I built a single array that includes both. I show the code for my first file below. I originally used a for-loop in the second program to select out the data. I like this code, so I also posted the entire thing below (It includes good formatting of all printed text.). Lastly, not posted, I wrote the second program using a while-loop to select the data. The while(1==1) I added to both of my second programs after watching the video. Thanks for the great lessons! ###################################################### File 1: Creates Pickle File #########################################3 #PaulMcWhorter - Python Beginners #Lesson 15: Saving and Reading Data Files With Pickle #The Write File: HWPickleA #by Jonathan Landers #May 20,2023 ### Homework: Python File 1 ### ''' This homework requires two python files. The 1st python file prompts the user for a list of student names and their average grades. The program saves this data in a pickle file as an array. The 2nd python uploads the pickle file and prompts the user for a student name. If the student name is in the data on the pickle file, the program gives the average grade of that student. ''' #Import pickle library (included in python download). import pickle #Create Data. StudentNum = int(input('How many students do you have?:')) StGrad = [] for j in range(0,StudentNum,1): x = str(input('What is your students name?: ')) y = float(input("What is this student's average grade?: ")) StGrad.append([x, y]) #Create pickle file and dump data into it. with open('PaulMcWhorterPythonBeginners15HWPickle.pkl', 'wb') as p: pickle.dump(StGrad,p) pickle.dump(StudentNum,p) #Running the program will creat the pickle file. ############################# File 2: Uses Pickle File ######################################### #PaulMcWhorter - Python Beginners #Lesson 15: Saving and Reading Data Files With Pickle #The Write File: HWPickleWhile #by Jonathan Landers #May 20,2023 ### Homework: Python File 2 ### ''' This homework requires two python files. The 1st python file prompts the user for a list of student names and their average grades. The program saves this data in a pickle file as an array. The 2nd python uploads the pickle file and prompts the user for a student name. If the student name is in the data on the pickle file, the program gives the average grade of that student. ''' #Import pickle library (included in python download). import pickle #Upload pickled data. with open('PaulMcWhorterPythonBeginners15HWPickle.pkl', 'rb') as p: stgrad = pickle.load(p) stnum = pickle.load(p) ''' Paul McWhorter's addition: We want this part of the program to run forever so that the user does not need to restart the program every time around. So, create a while loop that runs so long as 1 = 1, which is always true. ''' while (1==1): #Ask user for student name. nameRequest = str(input('What is your students name?: ')) st = 'nothing' grad = 0 #Find out if requested name is in pickle file. #If data is in pickle file, create a variable for the student name and for that student's grade for i in range (0,stnum,1): if(nameRequest == stgrad[i][0]): st = stgrad[i][0] grad = stgrad[i][1] if(nameRequest != stgrad[i][0]): stnot = 'Name not in the list. Please enter a different name.' gradnot = int(0) #Print out the studen't name with their grade if available. #Otherwise, tell user that the student's name is not in the list. if(grad != 0 and st != 'nothing'): ststr = str(st) gradstr = str(grad) print('') print(ststr , 'has an average grade of' , gradstr + '.') print('') else: stnotstr = str(stnot) print('') print(stnotstr) print('')
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@timothyboyd4346
@timothyboyd4346 2 жыл бұрын
I am legend! This was the first time I've gotten pickle to work thank you!
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Nice job!
@madsci6807
@madsci6807 Жыл бұрын
I am legend! easier than the last assignment. Separated it into two programs, one for the input, and one to retrieve the data. got a little messed up at first with the pickle storage, but figured it out.
@EFoxVN
@EFoxVN 2 жыл бұрын
"I am legend". But I could only do it after I allowed my brain to go into a different state. At first I had no clue what to do. And then later, inspiration came. And thanks, I really have a lot of fun!! Many blessings from South Africa!
@kamwilliams9085
@kamwilliams9085 2 жыл бұрын
I AM LEGEND!!! lol Finally after unsuccessful attempts these past few assignments. My syntax isn't as complex as yours, I didn't include the name in the response but It worked so its a moral win for me!! I will include your pro tips next time.. Thanks!
@danielsaenz5570
@danielsaenz5570 2 жыл бұрын
I am LEGEND!! Thanks for all these lessons!!!
@RobVollmar
@RobVollmar 2 жыл бұрын
Paul, I used a slightly different tack in the second program. Rather than creating an array for numGrade, I handled the indexing like this: j=0 student=input('Which students average would you like to check? ') for i in stuArray: if (student==i): print(student,'has an average grade of ',avgArray[j]) j=j+1
@Leonarco333
@Leonarco333 2 жыл бұрын
Similar to how I did it. It seemed like an elegant solution.
@jstro-hobbytech
@jstro-hobbytech Жыл бұрын
Funny how many ways to do it. I used just a while loop with an escape character so it only had to be a couple if statements incase the person didn't exist.
@pennyshen5269
@pennyshen5269 Жыл бұрын
Really love ur style sir.thanks a lot 😀!
@mahadf9321
@mahadf9321 2 жыл бұрын
Amazing video like always!
@mohsenr4434
@mohsenr4434 2 жыл бұрын
I did a more complicated homework and almost gave up before I could finally debug it even after watching this lesson for the second time haha.. But I finally did it. Thank you!
@mateobertin3376
@mateobertin3376 2 жыл бұрын
I fold up like a che... I AM LEGEND PAUL!!! THank you for your incredible lessons, I see your videos from Argentina.
@pralaymajumdar1206
@pralaymajumdar1206 3 жыл бұрын
Learn a lot sir.. Thank you. waiting for the next week.
@ylevite
@ylevite Жыл бұрын
LEGEND! Managed to do homework. I have never in my life done homework willingly :)
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@berryblades
@berryblades Жыл бұрын
I AM LEGEND! Back into it again and loving Python Paul, this was fantastic, its starting to feel like I may someday be able to write something that has real world use! I'm here after the New Arduino sessions and its about time I became a patreon and contributed something, I wanted to give you a small bulk donation to show my appreciation when I finished the Arduino sessions but KZbin wanted to tax it so that's no good. I will give what little I can through Patreon though!
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND! Appreiate the interest in helping out. Also, my paypal is paul.mcwhorter@gmail.com . For some people that is the best way to help.
@mikew877
@mikew877 3 жыл бұрын
Got the homework assignment to work!! It was fun!
@kingdavid_p
@kingdavid_p 3 жыл бұрын
I am legend. And I am finally caught up with your python tutorials. See you next week
@tiberiumihaescu5382
@tiberiumihaescu5382 2 жыл бұрын
I am Legend! Good to finally be back on track!
@dadrbaa9850
@dadrbaa9850 2 жыл бұрын
amazing ! Engineer . I love your way of Explaining. you made me so excited of Programming language and python 😍
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Awesome, thank you!
@bkairosh8164
@bkairosh8164 3 жыл бұрын
Quite keen to find out more information on accepting data from the web, arduino or other external sources, process them on Python and send them back for further action. Thank you Paul for all the lessons. Greeting from Kazakhstan.
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
Noted!
@martinlewis645
@martinlewis645 2 жыл бұрын
Took me a while. I had to walk away and come back the next morning. Legend.
@antrikshfulwani7087
@antrikshfulwani7087 Жыл бұрын
I AM LEGEND! I did something a little bit different: While entering the information about a student, I gave them a serial number, their name and their average marks. While reading, I gave them options to find the students' information using their serial number, name or average marks. Everything worked perfectly, because I understood everything perfectly, because you teach perfectly! Thank you for another amazing series.
@robinwood5833
@robinwood5833 3 жыл бұрын
Thank you Paul, lessons are fantastic from Robin Downunder
@Leonarco333
@Leonarco333 2 жыл бұрын
Boo yeah! Even overachieved a bit. I simplified the data transfer by condensing the student and grades vectors into a matrix and read the length in the new program. I used the same trick to use names in the input statements and in the second program I added a view all option to print all of the names and grades in a table. Using while loops instead of for loops made the formatting easier while calling corresponding indices in the matrix to keep names and grades together.
@legend1204
@legend1204 2 жыл бұрын
I AM A LEGEND!!!!! Thanks Paul
@edSabio572
@edSabio572 3 жыл бұрын
Outstanding!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@railcat7083
@railcat7083 2 жыл бұрын
Legendary, dude!
@DivyanshAgarwal-cj3ur
@DivyanshAgarwal-cj3ur 18 күн бұрын
Just love your vedios Learning alot from your tutorial s❤
@jopiehattingh5351
@jopiehattingh5351 5 ай бұрын
Thank you very much the time and effort you put into the lessons Paul. Just happend to stumble upon yout lessons and learning a ton! I'm sure that like myself it's really appreciated by many. I must be honest it did not dawn on me to simply pickle the value for the number of entries to repeat and read it in for my loop in the read program. I ended having to do a bit reading/cheating and ended up using "len" to get the size of the array/list. Seems kind of obvious once I saw your solution...and so we learn :-) After getting it working tried to be a little morw fancy and add to the lesson by putting in a loop in to repeat the request for a name and display "not found" should the student name be entrered incorrectly or doesn't exit but admittedly folded pretty bad there. Looks like a little more loops and if statement practice is required and of course "fuel.
@polito-yd8fp
@polito-yd8fp 10 ай бұрын
I was able to do it but using while loops, for loops seemed a little hard at first so I understood after I watched you now 😂
@TheFleetz
@TheFleetz 3 жыл бұрын
Hope things are going well for you in South Africa Paul.
@patis.IA-AI
@patis.IA-AI Жыл бұрын
again great simple comprehensif top dot "nounours"
@scrappybobbarker5224
@scrappybobbarker5224 2 жыл бұрын
Thanks for the Video!
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Our pleasure!
@starRunnerX
@starRunnerX 2 жыл бұрын
I am a baby Groot legend. I easily got the first part, yet could not figure out the last half of the second HW. Your if statement, inside a for loop, inside a while loop really through me for a loop! I could envision something like that, I just could not for the life of me make it work with a string, instead of an int. I have now joined your Patreon. Thank you Mr. Paul, your tutorials have really helped me out. Would a robotics with Python every be a thing you'd do?
@architjain1908
@architjain1908 3 жыл бұрын
I put all the names and grades in one array as they are inputted so there every two entry is a name and other every two is the grades right after the name. For, "if name==names[i]", I out i as increments of two and if the asked name was the name, then the grade would be [i+1]. Hope that works great as well. Thank You!!
@advancedperformance9721
@advancedperformance9721 2 жыл бұрын
Thank you sir God bless you 🙏
@patfacunla1687
@patfacunla1687 2 жыл бұрын
I am legend Paul thanks to you!!!
@jaeyounghong8099
@jaeyounghong8099 Жыл бұрын
My code was similar, and my code worked perfectly fine. However, I didn't input dump and load print the data using two different programs. Although I understood this assignment, I am not satisfied because I watched your solution video before finishing the 2% left. Hopefully next time, I'll fully do it on my own. Thanks for the python lessons, Paul! Here after completely all the Arduino lessons~
@codecage9333
@codecage9333 3 жыл бұрын
Anxiously awaiting the solution to see how my program compares.
@chalmerditmars7037
@chalmerditmars7037 Жыл бұрын
I did it quite a bit different than you. I stored the student and grade in pairs in a data file and only pickled 1 file. Then I used len of that file to get my range of i and did not run the loop forever. In the loop it pulled the pair and checked the first half for match with the name that was input and then I printed "The average grade of x is y. Good lesson. I notice you only have about half as many likes now. Did some of those guys go down in their lawn chair and still laying out in the Walmart parking lot?
@arnaudmasse7839
@arnaudmasse7839 2 жыл бұрын
was able to do it on my own ! I am legend!!!!
@maku5289
@maku5289 Жыл бұрын
I am NOT legend... damnit was so close but I forgot to write 'range' in my loop of program 2, was surprisingly working for 3 and below, but over 4 students it would bug. 5-day-in-a-row 💥☕ Amazing content as always. 🤟
@ricardobjorkeheim775
@ricardobjorkeheim775 3 жыл бұрын
nice solution Paul:)
@colepdx187
@colepdx187 2 жыл бұрын
Fun assignment. I added some functionality. Normalized 'name' using the capitalize() method, added 'list' feature to list all records. Used rjust() and ljust() methods to nicely format the output of the list. Program loops until a blank name is entered in case you don't know how many names you have to enter and/or want to display multiple records. There's still this huge elephant in the room that if you enter a string at the grade prompt there is an unhandled program exception.
@jstro-hobbytech
@jstro-hobbytech Жыл бұрын
This homework was cool. I built on everything we already did except the +name+ to keep on the same line. I couldn't get that part so the output wasn't perfect. I used a while for the second program with an escape character. I got away without a a loop within a loop.
@ernestomendoza4862
@ernestomendoza4862 2 жыл бұрын
I am a legend! I did it a little differently. My array elements are vectors of three elements, the student ID, the student name, and the student grade. Then I can a specific name / grade by selecting the ID.
@amayaphotos8016
@amayaphotos8016 Жыл бұрын
At first i forgot to do the load stuff, but then i figured it & yeah, I AM A LEGEND
@paulmcwhorter
@paulmcwhorter Жыл бұрын
LEGEND!
@TheScissorunner
@TheScissorunner 2 жыл бұрын
Because of Huckleberry! I am Legend! Amazed by how the print statement can help with understanding what the code is doing.
@vysakhak191
@vysakhak191 2 жыл бұрын
I recommended this tutorial series to two of my best friends.😎
@atesotheater6536
@atesotheater6536 3 жыл бұрын
Thank you 😊
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
No problem
@terrymurphy565
@terrymurphy565 2 жыл бұрын
I am Legend, looking forward to see if I did it the same as you. My program was very similar, used while instead of for loop. Also direct append my inputs using name.append(input('Please Enter Name: ')) this saves one line of code. Not sure if this could cause issues or not. Used this in previous lessons as well.
@dzeykop
@dzeykop Жыл бұрын
Thank you Sir, another great lesson! Your lessons are not wasted time (#NWT) for me and that is exactly what I want! 👍
@MuhammadRezaAlipour
@MuhammadRezaAlipour 8 ай бұрын
i did it. it was very easy
@boydrogers7227
@boydrogers7227 3 жыл бұрын
Nearly identical to mine. 2 notable differences: 1. Instead of "while(1==1):" I used "while(studentName!='x')" to give myself a way out of the program. 2 instead of a "for" loop for comparing the entered name to the list, I used a "while" loop with i=i+1 iteration so that when I got a match, I could set my iterator to max and quit comparing. Also after I watched your solution I switched from commas to pluses in my strings to eliminate unwanted spaces. BTW, the concatenation works with just the variable name, i.e. "print(name+"'s grade is "+grade)".
@paulmcwhorter
@paulmcwhorter 3 жыл бұрын
Nice!
@darryng
@darryng 2 жыл бұрын
Excellent Tutorials! Busy with the Jetson Nano! Is there any chance you could do a series on the ESP32 with the ESP-IDF on VS Code? Much Appreciated!
@pateekdarnal2256
@pateekdarnal2256 3 жыл бұрын
I am legend thankyou sir may god bless you
@jimsimpson1006
@jimsimpson1006 6 ай бұрын
Output of the first program: How many students are in the class? 3 Please enter the student's name: James Please enter the student's average mark: 90 Please enter the student's name: Alice Please enter the student's average mark: 92 Please enter the student's name: Bob Please enter the student's average mark: 93 Thanks, that's all the data entered Output of the second program: Which student's average mark do you wish to see? Alice Alice obtained an average mark of 92.0 I learnt A LOT from this lesson, especially about saving data to a file. It’s getting to the stage where we can start doing actual useful stuff with Python!
@Mahin9994
@Mahin9994 5 ай бұрын
I AM LEGEND! And 'YOU ARE A GENIUS in ART OF TEACHING'! Stay Blessed and LiVE LoNG!!!
@paulmcwhorter
@paulmcwhorter 5 ай бұрын
LEGEND!
@Captain_Vitorio_Muscovy
@Captain_Vitorio_Muscovy Жыл бұрын
I chose to use only 1 list, personal preference. My code for the programs bellow: Program 1 import pickle num_students = int(input("How many students you have?: ")) student_grade_list = [] N = 0 while N < num_students: student_name = input(f"Please input the name of student nº{N+1}: ") student_grade = float(input(f"Please input {student_name}'s grade: ")) student_grade_list.append(student_name) student_grade_list.append(student_grade) N += 1 with open("Student_Data.pkl", "wb") as SG: pickle.dump(student_grade_list, SG) Program 2 import pickle student = input("Please inform the student's name: ") N = 0 with open("Student_Data.pkl", "rb") as SG: name_grade = pickle.load(SG) while name_grade[N] != student: N += 1 if name_grade[N] == student: print(f"{student}'s grades average is {name_grade[N+1]}")
@ecassar1975
@ecassar1975 2 жыл бұрын
I managed to do the homework. Did slightly different from you in that instead of using for in range loop I used while loops. Otherwise everything was pretty similar.
@Joel-pl6lh
@Joel-pl6lh 2 жыл бұрын
I did not know I had to create another file, so I paused the video and did it (Because I am a legend). I also added an option to exit the program and a message in case the name entered does not exist in the pickle file
@camilo40
@camilo40 2 жыл бұрын
legend
@samuelsavangouder5102
@samuelsavangouder5102 2 жыл бұрын
Hey Paul, can I use a while loop to take the input(names and marks) from the user? Instead of the for loop as you did. Ex: j = 0 while (j < numStudent): .... .... .... j += 1 Is this the correct way of doing it?
@hoanglinhnguyen607
@hoanglinhnguyen607 2 жыл бұрын
I AM LEGEND, so happy to do it on my own
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
LEGEND!
@criptosauro4587
@criptosauro4587 Жыл бұрын
the "while 1==1" is to keep asking, I solved the Homework this way: import pickle #get the info out with open("datos de los estudiantes.pkl", "rb") as f2: N= pickle.load(f2) G= pickle.load(f2) print(N) print (G) # What student are you interested in? ask = input("What student are you interested in? ") student_num = N.index(ask) print("The grade of", ask , "is: ") print(G[student_num])
@polito-yd8fp
@polito-yd8fp 10 ай бұрын
I am Legend, had some stress and thought through it
@paulmcwhorter
@paulmcwhorter 10 ай бұрын
The more you stress, the more rewarding it is when it works.
@maggit13
@maggit13 2 жыл бұрын
I am LEGEND!! total beginner at this and I got it to run. I also added in if the name is invalid, it says it's not in the list. Also added asking if the user wants to continue entering names, if not, it drops out of the while loop. Is it possible to use data sets like you had in the last lesson and have it search through multiple arrays instead of using separate arrays as the variables? or is that more advanced? Thanks again Paul!
@user-ix5hr1tu3k
@user-ix5hr1tu3k 2 жыл бұрын
i am legend ,i had a lot of fun doing it
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
LEGEND!
@elyeslaalai1062
@elyeslaalai1062 3 жыл бұрын
I was a legend!
@matthiass.9249
@matthiass.9249 3 жыл бұрын
I am a legend!
@charlielowell4077
@charlielowell4077 2 жыл бұрын
I might have missed where you mentioned it, but I didn't realize that I could use the same "for" loop to input both the name and the grade at the same time. For some reason I misunderstood that a for loop was only used for a single operation. I spent an hour trying to figure out how to associate name[n] with grade[n] after they had been put in their respective lists as a result of passing through two separate for loops. Finally gave up and watched your code. Really don't feel like a lawn chair after that, though. Really.
@Godsbeloved05
@Godsbeloved05 2 жыл бұрын
I am legend on first try!!!!
@paulmcwhorter
@paulmcwhorter 2 жыл бұрын
Yes you are!
@timwilliams9100
@timwilliams9100 Жыл бұрын
I am LEGEND!
@RDKCREATIONS
@RDKCREATIONS 3 жыл бұрын
Hi sir can you add a series of kali Linux
@briangraham910
@briangraham910 6 ай бұрын
Great lessons! When I alter the code, (I have autosave on), the program doesnt update. All the other programs are fine but for this one I literally need to close VS Studio and reload the program to reflect changes. I found out the hard way...I tried to code it myself, but it was always giving me errors. I would update the code but get the same error. After realizing the results weren't changing, I reopened VS Studio and viola! I tried to add code that if you enter a name not in the list, it would return a print("No records found" but I wasn't successful. I gave up because everytime I add or remove code I need to close and reopen VS Studio. Any thoughts? Thanks
Python Tutorial 16: Understanding Python Functions
34:26
Paul McWhorter
Рет қаралды 23 М.
Python Tutorial 18: Understanding Python Methods and Classes
42:43
Paul McWhorter
Рет қаралды 24 М.
1❤️
00:17
Nonomen ノノメン
Рет қаралды 13 МЛН
HOW DID HE WIN? 😱
00:33
Topper Guild
Рет қаралды 40 МЛН
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 54 МЛН
Python Tutorial 19: Python Classes and Methods Homework Examples
57:57
Master Python With This ONE Project!
56:54
Tech With Tim
Рет қаралды 11 М.
Python Tutorial 14: Saving and Reading Data Files With Pickle
22:57
Paul McWhorter
Рет қаралды 28 М.
Python Tutorial 12: Simple Python Sorting Program
27:00
Paul McWhorter
Рет қаралды 24 М.
Where Does Bad Code Come From?
42:21
Molly Rocket
Рет қаралды 185 М.
Olympiad mathematics | indian math
3:07
Mathist
Рет қаралды 355
Python Tutorial 10: Homework Solution for Averaging Numbers
20:41
Paul McWhorter
Рет қаралды 23 М.
Python 3D Graphics Tutorial 4: Understanding 3D Graphic Parameters
32:16
Battery  low 🔋 🪫
0:10
dednahype
Рет қаралды 414 М.
iPhone 15 Pro в реальной жизни
24:07
HUDAKOV
Рет қаралды 204 М.
Урна с айфонами!
0:30
По ту сторону Гугла
Рет қаралды 8 МЛН