WEBVTT

00:00.000 --> 00:05.000
Building program and debugging.

00:05.000 --> 00:09.000
We'll be understanding how to build a number guessing game.

00:09.000 --> 00:13.000
Debug the program. Let's understand what we are trying to do.

00:13.000 --> 00:16.000
The program picks a secret number between 1 to 20.

00:16.000 --> 00:23.000
After each guess, the program will tell you if it's too high, too low, or correct.

00:23.000 --> 00:26.000
You have limited chances to guess.

00:26.000 --> 00:31.000
Let's start. Generate a random number. Import random.

00:31.000 --> 00:42.000
We have imported and random module. The random module in Python is a built-in library that provides functions to generate random numbers and make random selections.

00:42.000 --> 00:52.000
Type, secret, number equals to random dot. Random open parenthesis, 1 comma 20 close parenthesis.

00:52.000 --> 01:00.000
The random function from the random module generates a random number between two specified values, including both.

01:00.000 --> 01:04.000
It sets a new secret number each time you start the game.

01:04.000 --> 01:09.000
Set the player's attempts to 5. Attempts equals 5.

01:09.000 --> 01:13.000
We will show the game title and add instructions to the player.

01:13.000 --> 01:18.000
Print. Guest the secret number game, backslash n.

01:18.000 --> 01:24.000
The backslash n tells Python to leave a blank line after this sentence.

01:24.000 --> 01:27.000
Print. Keep entering number until you guess it correctly.

01:27.000 --> 01:30.000
Print. Line. Backslash n.

01:30.000 --> 01:36.000
Create a loop for guessing for space underscore and range. Attempts.

01:36.000 --> 01:42.000
Guest equals to int. Input. Guest the number between 1 to 20.

01:42.000 --> 01:51.000
As we are stored the information in the form of a string, we need to add int, function, so that when the player enters the number, it takes it as an integer.

01:51.000 --> 01:54.000
Then, run the loop to check if it works correctly.

01:54.000 --> 02:00.000
Debug the program. Python has shown an error online eight. Let's fix it.

02:00.000 --> 02:08.000
If we check the code, we will understand that we have not closed the quotation marks. Add the end quotation mark.

02:09.000 --> 02:14.000
Now run the program. We will see the text printed. Check the player's guess.

02:14.000 --> 02:23.000
You will use conditionals, if, else, if, and else to check whether the guess is correct, too high or too low.

02:23.000 --> 02:32.000
We will add a if condition, if guess equals secret number. Print. Congratulations. You've guessed the correct number.

02:32.000 --> 02:43.000
Break. The break statement stops the loop at that moment. When the player guesses the secret number correctly, there's no need to continue asking for guesses.

02:43.000 --> 02:56.000
We will add an else if and else condition. Lif. Guest is greater than secret number. Print. Too high. Else. Print. Too low.

02:56.000 --> 03:02.000
We have nearly completed the program. Let's run it to check if it works. Debug the program.

03:02.000 --> 03:11.000
We will only get the most recent error on the console, which is online nine. Syntax error. Expected.

03:11.000 --> 03:16.000
We have not added the colon after secret number. We will add the colon.

03:16.000 --> 03:22.000
The colon helps the program understand that the following indented lines are part of the if statement.

03:23.000 --> 03:31.000
Click on run to check whether the code is working. There is one more error online, 12, which needs to be fixed.

03:31.000 --> 03:38.000
In the alif condition, if the player's guess is greater than secret number, it should print too high.

03:38.000 --> 03:45.000
But we haven't included the greater than sign in the statement. Add greater than sign.

03:46.000 --> 03:52.000
We will check if the code runs properly. Now the code is executed properly. End the game.

03:52.000 --> 04:03.000
To end the game, we will add a statement. Else. Print. F. Sorry. You've run out of attempts. The correct number was secret number.

04:03.000 --> 04:11.000
It is important to add F, formatted string, so we get the secret number printed in the console after all incorrect attempts.

04:12.000 --> 04:21.000
Let's run a check whether we can find the secret number.

04:21.000 --> 04:31.000
Congratulations on building your first number guessing game. Exploring these ideas will help you enhance your programming knowledge.

