Coding Exercise for Beginners in Python with solution | Exercise 23 | Python for Beginners #lec68

Jenny's Lectures CS IT
6 Jun 202307:58

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

00:00

📚 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.

05:01

💻 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

Python is a high-level, interpreted, and general-purpose programming language known for its readability and ease of use. In the video, the presenter is teaching Python as part of a learning series, indicating that the language is the primary tool for the coding exercises discussed.

💡Dictionaries

A dictionary in Python is a collection of key-value pairs. It is used to store data in a way that maps keys to values, making it ideal for representing real-world entities and their attributes. In the script, dictionaries are used to represent student marks, where the student's name is the key and their marks are the values.

💡Coding Exercise

A coding exercise is a task designed to help learners practice and apply programming concepts. In the video, the presenter introduces a coding exercise that involves converting student marks into grades using a dictionary, demonstrating the practical application of Python dictionaries.

💡Grades

Grades are the evaluations given to students based on their performance. In the context of the video, the presenter outlines a grading system where numerical marks are converted into letter grades (A+, A, B+, etc.), showcasing how conditional logic can be applied in programming.

💡Conditional Statements

Conditional statements are programming constructs that execute different blocks of code based on whether a condition is true or false. The script describes using 'if' conditions to determine the grade a student receives based on their marks, illustrating a fundamental concept in programming logic.

💡Loops

Loops are used in programming to repeat a block of code multiple times. The script mentions a 'for' loop to iterate over the keys in a dictionary, which is a common technique for processing collections of data in Python.

💡Key-Value Pairs

In the context of dictionaries, key-value pairs are the fundamental units of data storage, where each key is associated with a value. The video script uses the student's name as the key and their marks as the value, emphasizing the importance of understanding how to access and manipulate these pairs in Python.

💡Empty Dictionary

An empty dictionary in Python is a dictionary with no key-value pairs. The script instructs the creation of an empty dictionary to store student grades, which will be populated as the program runs, demonstrating how data structures are initialized and used in programming.

💡Nested Dictionaries

Nested dictionaries are dictionaries that contain other dictionaries as values. Although not explicitly mentioned in the script, the concept is implied when discussing the creation of a new dictionary based on an existing one, suggesting a deeper level of data organization in Python.

💡Data Conversion

Data conversion refers to the process of changing data from one form to another. In the video, the presenter guides viewers on how to convert numerical marks into letter grades, which is a form of data conversion that demonstrates how programming can be used to manipulate and interpret data.

💡Logical Conditions

Logical conditions are used in programming to evaluate expressions and control the flow of a program. The script describes using conditions such as 'greater than' and 'less than' to assign grades based on marks, highlighting the use of logical operators in decision-making within a program.

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

play00:00

hey everyone I hope you all are safe and

play00:01

doing good so in the series of learning

play00:03

Python programming language in the

play00:04

previous video we have discussed about

play00:05

dictionaries in Python right now in this

play00:09

video we will see when coding exercise

play00:11

based on dictionary so I would recommend

play00:13

please watch out that video first then

play00:15

come to this video now what is this

play00:17

coding exercise

play00:18

first thing we have a dictionary right

play00:21

now we have like marks of students in

play00:25

the form of dictionary as you can see on

play00:27

my screen this is a dictionary student

play00:28

Mark and here I am having name of the

play00:31

students and their marks right names are

play00:35

keys and their marks are values key and

play00:38

value pair we are having this dictionary

play00:40

we have so you can note down this thing

play00:42

now what you have to do you have to

play00:44

write down a program that will convert

play00:46

these given marks into grades

play00:51

so basically now you have to make

play00:54

another dictionary whatever name you can

play00:56

take like student underscore grade you

play00:58

can take and in that dictionary name of

play01:01

the students would be as a tease but

play01:03

rather than marks grades would be there

play01:08

you have to convert those marks into

play01:11

grades and what are the criteria

play01:13

if marks are between 91 200 then grade

play01:16

is a plus 81 to 90 a 71 to 80 B plus

play01:20

like this this is the grading system you

play01:23

have to provide below 40 it's F so you

play01:26

can just note down this thing also okay

play01:28

now you have that student marked

play01:31

dictionary you have the grading system

play01:33

now you have to convert

play01:36

you have to just access what marks of

play01:38

the student and you have to put if

play01:40

condition if grade is between this then

play01:43

like grade so like you know marks is

play01:46

greater than 90 so grade is a plus so

play01:48

what you will do

play01:50

the hint is you can take an empty

play01:52

dictionary student grade and in that

play01:54

dictionary you can just put student

play01:55

names and then

play01:57

grade rather than marks

play01:59

I hope now we are getting my point so

play02:02

please laugh pause the video and give it

play02:04

a try

play02:05

so I hope you have tried this out now

play02:07

let's do this exercise together create a

play02:10

new file and you'll see we'll write down

play02:14

coding exercise

play02:16

underscore

play02:17

dictionaries date Dot py okay now just

play02:24

make that same student marks that

play02:27

dictionary okay

play02:29

so now this dictionary we have student

play02:31

marks

play02:32

how how you will do that thing to access

play02:35

these marks using keys we can access

play02:39

so you have to Loop through this

play02:40

dictionary first gen you will access

play02:43

then marks then on marks will put some

play02:44

condition then Harry then marks them on

play02:47

that we'll put some condition so for

play02:49

Loop four

play02:51

student in

play02:54

student marks

play02:56

see this thing we have discussed in

play02:57

previous video if I write down this

play02:59

thing then this student this for Loop if

play03:02

I print student then this for Loop will

play03:03

access all the keys all the keys only

play03:06

right

play03:08

that way that's why I recommend you to

play03:10

watch previous video first so now

play03:12

in student we are having first Jenny

play03:14

then Harry dimpy Rahul aniketh and Prem

play03:16

like this so according to this journey

play03:19

we can access the marks how we can

play03:21

access the marks

play03:23

we are taking a variable marks and how

play03:25

we will access

play03:27

the dictionary name student marks and in

play03:30

bracket just provide the key so first

play03:34

key would be in student this variable

play03:37

right

play03:38

so first time in student in this

play03:40

variable what would be assigned

play03:43

generally

play03:46

now student marks Jenny student marks

play03:49

Jennifer and marks is the student

play03:50

magazine in 92 so 92 would be fetched in

play03:52

this line and in marks now we have 92.

play03:57

now we can put condition on marks so if

play04:01

Mass greater than 90 okay

play04:06

then

play04:07

now what you have to make because you

play04:10

will not change in this dictionary so we

play04:12

will make a second dictionary so let's

play04:14

take an empty dictionary

play04:16

student grade

play04:19

this is what it's an empty dictionary

play04:21

now in student grade we have to put

play04:27

the student name as key and

play04:30

this grade of the student as

play04:35

values right so

play04:38

the name of the dictionary is student

play04:40

grades empty dictionary and in bracket

play04:44

same obviously the name should be same

play04:47

these Keys would be same in both the

play04:49

dictionaries so just same key student

play04:52

whatever the case student

play04:54

and here what you will assign

play04:56

according to this grade is a plus

play05:01

I hope you heard this process see now

play05:03

marks till now marks 92 so check 92

play05:07

greater than 90 yes condition true

play05:08

condition true means you will enter in

play05:10

this control and student grade this is

play05:13

an empty dictionary in student right now

play05:16

we are having Jenny so

play05:19

the key would be have to add an element

play05:21

that also we have discussed right so

play05:23

Jenny a plus would be added to this

play05:26

student grade first item Jenny a plus

play05:29

key and value pair right like this we

play05:31

will do for all the conditions right

play05:33

second condition is

play05:34

alif

play05:37

marks greater than 80.

play05:40

right in that case same in student

play05:43

grades and

play05:45

student

play05:47

what you will

play05:49

put a

play05:51

right

play05:53

like this I guess you can put all the

play05:55

conditions in else simply f

play05:58

and after that after this for Loop we

play06:01

are going to just print

play06:03

student grade this dictionary

play06:06

right

play06:08

so let's run this and see

play06:11

see

play06:12

Jenny a plus Harry B plus dimpy C Rahul

play06:17

D again A Plus and frame f

play06:22

I hope you got this see no need to put

play06:24

this condition maybe you are confused

play06:25

here you should put marks greater than

play06:27

80 and

play06:28

less than 90 no need to put these and

play06:32

condition because see if suppose let's

play06:35

take one condition one example marks 82

play06:39

so first thing first this if condition

play06:42

would be checked 82 greater than 90 no

play06:44

so obviously this will not enter the

play06:47

control will not enter into this if else

play06:49

if second condition is true yes then a

play06:52

would be printed suppose marks 92.

play06:56

first this if condition would be checked

play06:58

92 greater than 90 yes condition true so

play07:01

in this

play07:01

control we will enter in this block and

play07:03

a plus

play07:04

right

play07:06

so if this condition has been triggered

play07:08

then all the other condition would be

play07:10

skipped so no need to put logical and

play07:12

condition like greater than 80 and less

play07:14

than 90 greater than 70 and less than

play07:17

it is something like this no this one

play07:19

condition is NF now if you are not

play07:21

getting this thing you can just write

play07:23

down this thing uh all the you know code

play07:25

in a piece of paper and write on this

play07:27

thing with different different example

play07:29

different different marks of the

play07:31

students one by one with hand you can

play07:33

write on this and definitely it's not so

play07:35

messed up right so that's it and sorry

play07:38

to frame if anyone who is watching whose

play07:41

name is brain because

play07:42

I give only 34 marks

play07:45

but that is just an example okay okay so

play07:48

I hope you got this exercise this was

play07:49

not so much tough and actually we will

play07:52

see nested dictionaries as well as list

play07:54

so now I'll say the next video till then

play07:55

bye take care

Rate This

5.0 / 5 (0 votes)

関連タグ
Python ProgrammingCoding ExerciseDictionariesConditionalsGrade ConversionEducational ContentProgramming TutorialData StructuresStudent MarksGrade System
英語で要約が必要ですか?