Coding Exercise for Beginners in Python with solution | Exercise 23 | Python for Beginners #lec68
Summary
TLDRIn this Python programming tutorial, the focus is on converting student marks into grades using dictionaries. The video demonstrates how to create a dictionary with students' names as keys and their marks as values, then transform these marks into grades according to a specified grading system. The instructor guides viewers through writing a program that loops through the dictionary, applies conditional statements to assign grades, and stores these in a new dictionary. The video concludes with a practical coding exercise that reinforces the concepts discussed.
Takeaways
- 💻 The video is part of a series teaching Python programming language, specifically focusing on dictionaries.
- 📚 The previous video discussed dictionaries in Python, and this video builds on that knowledge with a coding exercise.
- 📝 The exercise involves converting student marks stored in a dictionary into grades using another dictionary.
- 🔑 The original dictionary contains student names as keys and their marks as values.
- 📊 The grading criteria are provided, with different ranges of marks corresponding to different grades (A+ for 91-100, A for 81-90, etc.).
- 📋 The video suggests creating an empty dictionary called 'student_grade' to store the converted grades.
- 🔍 The video demonstrates how to loop through the 'student_marks' dictionary to access each student's marks.
- 💡 It's explained that conditional statements (if-elif-else) are used to determine the grade based on the marks.
- 📝 The video provides a step-by-step guide on how to write the code for the exercise.
- 👨🏫 The instructor encourages viewers to pause the video and attempt the exercise before watching the solution.
- 🔗 The video concludes with a mention of future videos that will cover nested dictionaries and lists.
Q & A
What is the main topic of the video?
-The main topic of the video is a coding exercise involving Python dictionaries, specifically converting student marks into grades.
What is the structure of the student marks dictionary discussed in the video?
-The student marks dictionary has student names as keys and their corresponding marks as values.
What is the purpose of creating a new dictionary called 'student_grade'?
-The purpose of creating 'student_grade' is to store the student names as keys and their corresponding grades as values based on the marks obtained.
What are the grading criteria mentioned in the video?
-The grading criteria are: 91-100 for A+, 81-90 for A, 71-80 for B+, and below 40 for F. The video suggests using if-else conditions to assign these grades.
How does the video suggest looping through the student marks dictionary?
-The video suggests using a for loop to iterate over the keys (student names) in the student marks dictionary.
What is the significance of the variable 'marks' in the coding exercise?
-The variable 'marks' is used to store the value (marks) associated with each key (student name) in the student marks dictionary during the loop.
Why is it unnecessary to use 'and' conditions for the grade ranges in the if-else statements?
-It is unnecessary to use 'and' conditions because the if-else structure naturally progresses to the next condition if the previous one is not met, ensuring only one grade is assigned per student.
What is the final step in the coding exercise after assigning grades?
-The final step is to print the 'student_grade' dictionary which contains the student names and their corresponding grades.
How does the video handle students with marks below 40?
-For students with marks below 40, the grade 'F' is assigned in the else part of the if-else condition.
What is the recommendation for viewers who are confused about the if-else conditions?
-The video recommends writing down the code and manually testing it with different marks to better understand the logic.
Outlines
📚 Introduction to Python Dictionaries and Coding Exercise
This paragraph introduces a Python programming tutorial focused on dictionaries. The instructor begins by checking in with the audience and references a previous video on dictionaries. The main content is a coding exercise where the task is to convert student marks stored in a dictionary into grades using another dictionary. The exercise involves using conditional statements to assign grades based on mark ranges. The instructor provides a grading system and suggests creating an empty dictionary to store the student names as keys and their corresponding grades as values. The process includes looping through the original dictionary, accessing each student's marks, and applying conditions to determine the grade. The instructor encourages the audience to pause the video and attempt the exercise before proceeding.
💻 Implementing the Coding Exercise for Grade Conversion
The second paragraph delves into the coding exercise, providing a step-by-step guide on how to implement the grade conversion. The instructor demonstrates how to create a new Python file and use the student marks dictionary to access each student's marks. They explain how to use a for loop to iterate over the dictionary, access the marks, and apply conditional statements to assign grades based on the grading criteria. The instructor clarifies that there is no need for additional conditions once a grade has been assigned, as the if-else structure naturally handles this. They also provide a practical tip for understanding the logic by manually writing out the code and testing it with different mark values. The paragraph concludes with the instructor running the code and displaying the resulting dictionary with student names and their corresponding grades, emphasizing the simplicity of the exercise and looking forward to future topics like nested dictionaries and lists.
Mindmap
Keywords
💡Python Programming Language
💡Dictionaries
💡Coding Exercise
💡Grades
💡Conditional Statements
💡Loops
💡Key-Value Pairs
💡Empty Dictionary
💡Nested Dictionaries
💡Data Conversion
💡Logical Conditions
Highlights
Introduction to a Python programming language tutorial series.
Recommendation to watch the previous video on dictionaries before proceeding.
Explanation of a coding exercise involving a dictionary of student marks.
Demonstration of how to create a dictionary with student names as keys and marks as values.
Guidance on writing a program to convert marks into grades using a grading system.
Criteria for the grading system: A+ for marks 91-100, A for 81-90, and so on.
Instruction to create a new dictionary called 'student_grade' to store grades.
Advice on using an empty dictionary to store student names and their corresponding grades.
Tutorial on looping through the dictionary to access student marks.
Explanation of using if-else conditions to assign grades based on marks.
Example of how to handle edge cases like marks below 40 which are graded as F.
Emphasis on the importance of watching the previous video for understanding loops.
Step-by-step guide to creating a for loop to iterate over student marks.
Illustration of how to access dictionary values using keys in a loop.
Demonstration of using if conditions to check mark ranges and assign grades.
Advice on not using unnecessary logical AND conditions when one condition is enough.
Recommendation to practice the coding exercise by writing code on paper.
Conclusion of the exercise with a demonstration of the final output.
Anticipation of future videos covering nested dictionaries and lists.
Transcripts
hey everyone I hope you all are safe and
doing good so in the series of learning
Python programming language in the
previous video we have discussed about
dictionaries in Python right now in this
video we will see when coding exercise
based on dictionary so I would recommend
please watch out that video first then
come to this video now what is this
coding exercise
first thing we have a dictionary right
now we have like marks of students in
the form of dictionary as you can see on
my screen this is a dictionary student
Mark and here I am having name of the
students and their marks right names are
keys and their marks are values key and
value pair we are having this dictionary
we have so you can note down this thing
now what you have to do you have to
write down a program that will convert
these given marks into grades
so basically now you have to make
another dictionary whatever name you can
take like student underscore grade you
can take and in that dictionary name of
the students would be as a tease but
rather than marks grades would be there
you have to convert those marks into
grades and what are the criteria
if marks are between 91 200 then grade
is a plus 81 to 90 a 71 to 80 B plus
like this this is the grading system you
have to provide below 40 it's F so you
can just note down this thing also okay
now you have that student marked
dictionary you have the grading system
now you have to convert
you have to just access what marks of
the student and you have to put if
condition if grade is between this then
like grade so like you know marks is
greater than 90 so grade is a plus so
what you will do
the hint is you can take an empty
dictionary student grade and in that
dictionary you can just put student
names and then
grade rather than marks
I hope now we are getting my point so
please laugh pause the video and give it
a try
so I hope you have tried this out now
let's do this exercise together create a
new file and you'll see we'll write down
coding exercise
underscore
dictionaries date Dot py okay now just
make that same student marks that
dictionary okay
so now this dictionary we have student
marks
how how you will do that thing to access
these marks using keys we can access
so you have to Loop through this
dictionary first gen you will access
then marks then on marks will put some
condition then Harry then marks them on
that we'll put some condition so for
Loop four
student in
student marks
see this thing we have discussed in
previous video if I write down this
thing then this student this for Loop if
I print student then this for Loop will
access all the keys all the keys only
right
that way that's why I recommend you to
watch previous video first so now
in student we are having first Jenny
then Harry dimpy Rahul aniketh and Prem
like this so according to this journey
we can access the marks how we can
access the marks
we are taking a variable marks and how
we will access
the dictionary name student marks and in
bracket just provide the key so first
key would be in student this variable
right
so first time in student in this
variable what would be assigned
generally
now student marks Jenny student marks
Jennifer and marks is the student
magazine in 92 so 92 would be fetched in
this line and in marks now we have 92.
now we can put condition on marks so if
Mass greater than 90 okay
then
now what you have to make because you
will not change in this dictionary so we
will make a second dictionary so let's
take an empty dictionary
student grade
this is what it's an empty dictionary
now in student grade we have to put
the student name as key and
this grade of the student as
values right so
the name of the dictionary is student
grades empty dictionary and in bracket
same obviously the name should be same
these Keys would be same in both the
dictionaries so just same key student
whatever the case student
and here what you will assign
according to this grade is a plus
I hope you heard this process see now
marks till now marks 92 so check 92
greater than 90 yes condition true
condition true means you will enter in
this control and student grade this is
an empty dictionary in student right now
we are having Jenny so
the key would be have to add an element
that also we have discussed right so
Jenny a plus would be added to this
student grade first item Jenny a plus
key and value pair right like this we
will do for all the conditions right
second condition is
alif
marks greater than 80.
right in that case same in student
grades and
student
what you will
put a
right
like this I guess you can put all the
conditions in else simply f
and after that after this for Loop we
are going to just print
student grade this dictionary
right
so let's run this and see
see
Jenny a plus Harry B plus dimpy C Rahul
D again A Plus and frame f
I hope you got this see no need to put
this condition maybe you are confused
here you should put marks greater than
80 and
less than 90 no need to put these and
condition because see if suppose let's
take one condition one example marks 82
so first thing first this if condition
would be checked 82 greater than 90 no
so obviously this will not enter the
control will not enter into this if else
if second condition is true yes then a
would be printed suppose marks 92.
first this if condition would be checked
92 greater than 90 yes condition true so
in this
control we will enter in this block and
a plus
right
so if this condition has been triggered
then all the other condition would be
skipped so no need to put logical and
condition like greater than 80 and less
than 90 greater than 70 and less than
it is something like this no this one
condition is NF now if you are not
getting this thing you can just write
down this thing uh all the you know code
in a piece of paper and write on this
thing with different different example
different different marks of the
students one by one with hand you can
write on this and definitely it's not so
messed up right so that's it and sorry
to frame if anyone who is watching whose
name is brain because
I give only 34 marks
but that is just an example okay okay so
I hope you got this exercise this was
not so much tough and actually we will
see nested dictionaries as well as list
so now I'll say the next video till then
bye take care
تصفح المزيد من مقاطع الفيديو ذات الصلة
Python Programming Practice: LeetCode #1 -- Two Sum
Percabangan If dan Switch Case
Conditional Statements | If-else, Switch Break | Complete Java Placement Course | Lecture 3
Pattern Printing | Problems on Loops - Part 1 | Lecture 7 | C++ and DSA Foundation Course
7 SDL Trados Studio: Creating AutoSuggest dictionaries
If Else Statements in Python | Python for Beginners
5.0 / 5 (0 votes)