While loop execution problem

i have tried to execute while loop program in python. But it always shows indentation error.
i am attaching the photo of the program, Could anyone help to solve the issue.

Check after opening while loop check whether you have put the ‘:’ symbol
then check if you have correctly left tab space
if it is showing error just go to each line inside the loop -press home- backspace till left most-- and press tab
read_five_times = “No”
count = 0
while read_five_times == “No”:
print (“Reading workshop…”)
count = count + 1
if(count == 5):
read_five_times = “Yes”

print (“Good Job ! You understood the workshop.”)

Hello @jayanth.chekkala
But in first line there is syntax error
in “No”
SyntaxError: invalid character in identifier

@ykoffice6920 there is an indentation error in your code at line 4 add space before read_five_times and print statement.

Hi @ykoffice6920, after the if condition you must give proper tab space for the statement below the if condition.Since you haven’t given that space the error occured.
Try the code below:

print(“Reading”)
count=count+1
if(count==5):
read_five_times=“Yes”
print(“GOOD”)

It is an indentation error. In python code blocking is done using indentation. So you have to put spaced for the codes which is inside the if condition.

@ykoffice6920

Please indent the code as per the instructions already provided in the training.

See where Ubuntu terminal is showing you the possible error. It shows that after the if statement it was expecting an indented block. In the code you wrote, you need to provide indentation to all the statements which fall under the if statement.

 if (count == 5):
     read_five_times = "Yes"
     print("Good")

I assume you hvae already initialized your count variable and you are incrementing its value inside the while loop. Python is extremely specific about the indentions(spaces you provide before each statement).
Identation helps in identifying whether a statement belongs to a particular control( a function or if/else condition/while etc) or not .
so the code should be indented as;

while(count<=5):
   print("Reading")
   count+=1
   if(count==5): 
     read_five_times="Yes"
     print("Good")

This will print Reading\nReading\nReading\nReading\nReading\nGood

hi@ykoffice6920 you should give a tab space before “read_five_times=“yes”” as it is inside a conditional statements. Any statements inside a conditional or loops must be given a tab space before them writing.

Here, after the if condition you must have to give the indentation that is,
if(count == 5):
read_five_times = “Yes”
print(“Good”)
Due to this you had an indentation error.

So using while loop you can write the code as:
count=0
while(count<5):
print(“Reading”)
count +=1
if(count == 5):
read_five_times = “Yes”
print(“Good”)

It’s clearly an indentation error.
Indentation refers to the spaces at the beginning of a code line. Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important.
Python uses indentation to indicate a block of code.
So the correct block of code is

Screenshot (335)

It is an indentation error only after using while and if you need to give some space in the next before print statement begin ,try in this way
for example
while t<0:
print(“hello”)
if t==0:
print(“hello world”)

I’m going to presume that you’ve previously created your count variable and that the while loop is incrementing its value. Python is very particular about indentions (spaces you provide before each statement).
Identification aids in determining whether a statement is a component of a specific control (such as a function, if/else condition, while, etc.).

The statement below the if statement should have a tab space, which is known as indentation. The correct way to write this is:
if(count == 5):
read_five_times = “Yes”

indentation is must in python leave a tab space after if statement so that after count reaches 5 it prints Yes

Indentation is important concept of python as here all the statements with same space to right ,belong to same code block.
for example-after while loop all statements till if block will have same indentation as they belong to same block.
while(count<=5):
print(“Reading”)
count+=1
if(count==5):
read_five_times=“Yes”
print(“Good”)

[/quote]

block indentation error in line 4

you first check all the statement with same space to right,belong to same code block.
I tried this code and the code are
read_five_times = “No”
count = 0
while read_five_times == “No”:
print (“Reading”)
count = count + 1
if(count == 5):
read_five_times = “Yes”
print(“Good”)

You may use this code for proper execution and before having the result you need to state the variable.

Count =0
while (count<=5):
print(“Reading”)
if (count==5):
print(“Good”)
break