Skip to playerSkip to main contentSkip to footer
  • 5/21/2025
A good beginner Python exercise is to create a simple "number-guessing game" where the computer randomly selects a number, and the user tries to guess it. This exercise reinforces basic concepts like random number generation, input/output, conditional statements, and loops.
Transcript
00:00exercise solve
00:02exercise requirement
00:04is that
00:06string is mixed
00:08by capital characters
00:10and lower letters
00:12u is capital
00:14q is small letter
00:16count
00:18count
00:20and small letters
00:22very simple
00:24exercise
00:26maximum concept
00:28we will start writing the code
00:34let's go
00:36we have a string
00:38we have a string
00:40we have a string
00:42we have a function
00:44we have a function
00:46which
00:48gives us
00:50capital letters
00:52and lowercase letters
00:54we have to do
00:56we have to do
00:58two categories
01:00capital letters
01:02and lowercase letters
01:04now
01:05which data structure
01:06can be best for this job
01:08when we have categories
01:10and only count
01:12of course
01:13we can't keep the list
01:14we can't keep the list
01:16so best
01:17is the example
01:18that we have a dictionary
01:20define
01:22let's say
01:24uppercase
01:26right
01:27and
01:28give it
01:29at the moment
01:30we have zero value
01:31and
01:32define it
01:34lowercase
01:36right
01:37and
01:38at the moment
01:39zero
01:40so we have a counter
01:42uppercase
01:43and lowercase
01:44i will call letter
01:46letter
01:48and lowercase letter
01:50which we have at the moment
01:51zero
01:52so we have these letters
01:54we have to count
01:55using a function
01:56but
01:58function
01:59is basically
02:00a wrapper
02:02right
02:03so wrapper
02:04we have to talk about
02:05main code
02:06which will calculate
02:07and count
02:08for count
02:09for count
02:10for count
02:11I can do
02:12this
02:13string
02:14is simple
02:15and for loop
02:16for individual element
02:17to return
02:18when the individual element
02:19comes to a
02:20q
02:21or u
02:22then
02:23I can do
02:24that upper
02:25or lower
02:26for
02:27let's say
02:28letter
02:29in
02:30string
02:31let's say
02:32s
02:34cos
02:35and
02:36convert
02:37just like this
02:39just like this
02:40for letter
02:41in
02:42string
02:43that is
02:44for
02:45letter
02:46in
02:47string
02:48for a letter
02:49in a string
02:50for a letter
02:51in a string
02:52now
02:53I can check
02:54what capital
02:55is
02:56capital
02:57is
02:59capital
03:00or not
03:01so
03:02if
03:03letter
03:04dot
03:06is
03:07upper
03:08function
03:09which exists
03:10which we can use
03:11or not
03:12so
03:13no problem
03:14no big deal
03:15we can use
03:16methods
03:17so
03:18is upper
03:19check
03:20is upper
03:21or not
03:22simply
03:23method
03:24sorry
03:25if
03:26upper
03:27is
03:28yes
03:29if
03:30upper
03:31is
03:32then
03:33we have
03:34dictionary
03:35now
03:36counter
03:37so
03:38this
03:39dictionary
03:40is
03:41counter
03:42so
03:43counter
03:44key
03:45basically
03:46which is
03:47upper case
03:48key
03:50you can add
03:52if
03:53it
03:54is
03:55no problem
03:56I have
03:57seen
03:58that
03:59if
04:00capital
04:01is
04:02counter
04:03then
04:04counter
04:05the
04:06value
04:07return
04:08will
04:09add
04:10one
04:11okay
04:12we have
04:13left
04:14left
04:15left
04:16left
04:17left
04:18left
04:19left
04:20one
04:22in
04:23case
04:25is
04:27lower
04:29in
04:30case
04:31lower
04:34lower
04:35on
04:36lower
04:37more
04:38more
04:39more
04:40just
04:41last
04:42have
04:43Parliament
04:45I
04:46reduился
04:47유
04:48of
04:49Now, because we have show results, I will give it a basic indentation level for indentation level
04:59and here I will print.
05:02First, let's say original string print.
05:07The original string is here.
05:24Now, result print.
05:28It is very simple.
05:29I will say that the number of uppercase letters is very simple.
05:43Now, I have a list to append.
05:46So, I will say that the number of uppercase letters is very simple.
05:55If you want unserer key to the answer, you will visit.
06:09And if you want to enable the number of uppercase letters.
06:13I will 2018 author keys.
06:17danachLES are full.
06:19LOWER
06:21lower. Okay, excellent.
06:24Now we will be able to do this work
06:27that we have to do this function.
06:30Now, if I have to count a string,
06:33then I will run this function.
06:35Sorry, this code is run directly.
06:38Before I will run this raw form,
06:41then I will wrap up and then I will run this function.
06:42I will execute it.
06:44As you see, the error is R,
06:46and it says that the uppercase letter is not defined.
06:51The reason is obvious that we have to do this function.
06:56Because this is a key.
06:58Now I will pass as a variable,
07:00which again is a mistake.
07:02Now I will execute it again.
07:05Let's see.
07:06Again, we have an invalid syntax.
07:09I will add parentheses.
07:12Okay, yes, here is a problem.
07:16Here is a problem.
07:18This problem is a problem.
07:20Okay, guys.
07:21This problem is because I have single string
07:24use for both purposes.
07:26So, this is why Python is confused.
07:28So, I already discussed this problem.
07:32If you have a single string
07:34use it,
07:35then you will make sure that you have double code
07:37use it.
07:38Now it will be okay.
07:39So, I will execute it.
07:40As you see,
07:41now I have count
07:43number of uppercase letters are 9,
07:45and lower case are 24.
07:46Now I will do this.
07:47Now I will do this.
07:48Okay.
07:49So, I will execute it.
07:50As you see,
07:51now I have count
07:52number of uppercase letters are 9,
07:53and lower case are 24.
07:54Now I will do this.
07:55Here we can add two line
07:57using escape character.
07:58This is escape character.
07:59When we connect
08:01to me,
08:02we can add this to the end.
08:03It will be true
08:04that the next step is
08:05in the end of the line.
08:06Basically,
08:07I will do this.
08:08I will throw this as 2
08:09line as a result.
08:11So,
08:12I will do this last step.
08:13As you see,
08:14we have now result
08:15that will come into the end,
08:16and this will display the result.
08:17in raw form,
08:17or when I have code or string,
08:20I will run this code.
08:25I have to tell you,
08:26the basic definition of function,
08:28I can use this as a wrapper.
08:30I will tell you,
08:32I have a function define,
08:34and say,
08:36let's say,
08:38cap counter,
08:40capital letter counter,
08:42which is as a parameter,
08:44as a parameter,
08:46I will give it a string,
08:48and then it will work.
08:52What will happen?
08:54I will perform this function.
08:56I will indent this level.
08:58When I need a result,
09:00I will basically,
09:02I will call this function,
09:04and I will give it a string.
09:08I will give it a string.
09:10Now,
09:12we expect to have the same result.
09:14as you see.
09:15However,
09:16if you change the value,
09:18that will be no problem,
09:20because we have a function,
09:22and we will run this code.
09:24In fact,
09:26we can add this code,
09:28and we can access this function,
09:30and we can access this function,
09:32just like this.
09:33And our code is simple.
09:34Basically,
09:35we will manipulate this string.
09:37So,
09:38let's do this again.
09:39So,
09:40I will add this string,
09:41and I will add this string.
09:42And I will add this string,
09:43and I will add this string,
09:44and I will add this string.
09:45Let's make it more interesting.
09:47And we will add this code,
09:49as we count as a number of letters.
09:50And I will add this string.
09:51which is the upper case letters and which is the lower case letters.
09:54So, I will copy this.
09:55Now, remember that this is a multi-line string.
09:58Multi-line, single line is not.
09:59So, multi-line, what do we do?
10:01Three quotation marks, just like this.
10:04So, I will remove this.
10:06And remove this.
10:08Three quotation marks, string, and three quotation marks,
10:12close it.
10:13So, this is our code.
10:15I will convert this in multi-line string.
10:18Now, I will call this function.
10:21Let's see.
10:23Now, let's see.
10:24Our code is clearly telling us that your original code was this.
10:29And its formatting is the same.
10:31However, it says that your capital letters are 12.
10:34And lowercase letters are 272.
10:38Excellent. Congratulations guys.
10:40You have done a great job.
10:41So, here are 12s.
10:42And lowercase letters are 272.
10:46Excellent.
10:47Congratulations guys.
10:48You have done a great job.
10:49So, here are these lectures.
10:50We will close.
10:51See you in the next one.
10:52You have done a great job.
10:53You have done a great job.
10:54You have done a great job.
10:55You have done a great job.
10:56You have done a great job.
10:57You have done a great job.
10:58You have done a great job.
10:59You have done a great job.
11:00You have done a great job.
11:01You have done a great job.
11:02You have done a great job.
11:03You have done a great job.
11:04You have done a great job.
11:05You have done a great job.
11:06You have done a great job.
11:07You have done a great job.
11:08You have done a great job.
11:09You have done a great job.
11:10You have done a great job.
11:11You have done a great job.
11:12You have done a great job.
11:13You have done a great job.
11:14You have done a great job.
11:15You have done a great job.

Recommended