Python
1: Print Function
2: Escape Sequence
3: Comments
4: Escape Sequence as Normal Text
5: Print Emoji
6: Python as Calculator
7: Strings Concatenation
8: Input
9: int function
10: Variables
11: String Formatting
12: String Indexing
13: String Slicing
14: Step Argument
15: Some useful function and methods
16: Strip Method
17: Find and Replace method
18: Center method
19: If Statement
20: If else statement
21: Nested if-else Statement
22: if-elif-else statement
23: while loop
23.1: Example 1 while loop
23.2: Example 2 while loop
23.3: Example 3 while loop
24: Infinite loop
25: for loop
25.1: Example 1 for loop
26: break and continue statement
27: for loop with string
2: Escape Sequence
3: Comments
4: Escape Sequence as Normal Text
5: Print Emoji
6: Python as Calculator
7: Strings Concatenation
8: Input
9: int function
10: Variables
11: String Formatting
12: String Indexing
13: String Slicing
14: Step Argument
15: Some useful function and methods
16: Strip Method
17: Find and Replace method
18: Center method
19: If Statement
20: If else statement
21: Nested if-else Statement
22: if-elif-else statement
23: while loop
23.1: Example 1 while loop
23.2: Example 2 while loop
23.3: Example 3 while loop
24: Infinite loop
25: for loop
25.1: Example 1 for loop
26: break and continue statement
27: for loop with string
Chapter 21: Nested if-else Statement
A nested if-else statement refers to placing one if-else statement inside another if-else block.
print('It\'s a game in which you have to guess a number(number may be between 1-20).')
number = int(13)
g_num = int(input("Enter a number (between 1-20).: "))
if g_num==number:
print("You won the game.")
else:
if number>g_num:
print("too low.")
else:
print("too high.")
Output 1:
It's a game in which you have to guess a number(number may be between 1-20).
Enter a number (between 1-20).: 11
too low.
Output 2:
It's a game in which you have to guess a number(number may be between 1-20).
Enter a number (between 1-20).: 15
too high.
Output 3:
It's a game in which you have to guess a number(number may be between 1-20).
Enter a number (between 1-20).: 13
You won the game.