What is indentation error:expected an indented block? And how to fix it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

What is indentation error:expected an indented block? And how to fix it?

I have written a program and it is showing error on this line >>> country_time_zones.append(pytz.timezone(country_time_zone)) >>> Pointing towards "u" in country_time_zone. https://code.sololearn.com/cBLVmft65cB1/?ref=app

26th Nov 2020, 7:20 AM
Yadav Shailendra
Yadav Shailendra - avatar
16 Answers
+ 4
https://code.sololearn.com/cLQHVj0tmuC9/#py
26th Nov 2020, 8:03 AM
Angelo
Angelo - avatar
+ 3
In python, to tell a line is inside a scope, you have to indent (tab) that line
26th Nov 2020, 7:28 AM
Angelo
Angelo - avatar
+ 3
Ok, wait a minute
26th Nov 2020, 7:31 AM
Angelo
Angelo - avatar
+ 3
See in python when you are using class, def, if, loop etc you use a sign ' : ' so for eg for i in range(10): print(i) i += 1 print(i) in above program after for loop's ':' you can see a tab space . Jaha Jaha yeah space hoga vo vo line samaj jao for loop ke haath mein hai, agar space mein garbari aayi means INDENTATION ERROR
28th Nov 2020, 1:01 AM
Priyanshi
Priyanshi - avatar
+ 2
Check if the indentation is right (you have to be consistent in the use of tabs OR spaces) in this or the preavius line
26th Nov 2020, 7:24 AM
Angelo
Angelo - avatar
+ 2
There is no indentation at all!
26th Nov 2020, 7:26 AM
Angelo
Angelo - avatar
+ 2
I know I can understand! Maybe if you correct that you will get any other error I was just trying to make a world clock using python.
26th Nov 2020, 7:39 AM
Yadav Shailendra
Yadav Shailendra - avatar
+ 2
Too many errors and issues to list. Review line by line and compare changes. May be best to view on PC or in landscape mode due to line length. https://code.sololearn.com/cv2I7WtL353I/?ref=app
26th Nov 2020, 8:01 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Thank you guys
26th Nov 2020, 8:31 AM
Yadav Shailendra
Yadav Shailendra - avatar
26th Nov 2020, 7:25 AM
Yadav Shailendra
Yadav Shailendra - avatar
+ 1
I still didn't understand can you please post the code by correcting it 🙏🙏🙏
26th Nov 2020, 7:31 AM
Yadav Shailendra
Yadav Shailendra - avatar
+ 1
from datetime import datetime import pytz Country_Zones ['America/New-York', 'Asia/Kolkata', 'Australia/Sydney', 'Canada/Atlantic','Brazil/East','Chile/EasterIsland', 'Cuba', 'Egypt', 'Europe/Amsterdam', 'Europe/Athens','Europe/Berlin', 'Europe/Istanbul', 'Europe/Jersey', 'Europe/London', 'Europe/Moscow','Europe/Paris', 'Europe/ Rome', 'Hongkong', 'Iceland', ' Indian/Maldives', 'Iran', 'Israel', 'Japan','NZ', 'US/Alaska', 'US/Arizona', 'US/Central', 'US/East - Indiana'] country_time_zones = [] for country_time_zone in Country_Zones: #you need tab here and the #text editor doesn't allow #tab. country_time_zones.append(pytz.timezone(country_time_zone)) for i in range(len(country_time_zones)): #also here country_time = datetime . now (country_time_zones [i]) print(f"The date of {Country_Zones [i]} is {country_time. strftime ( "%d-Xm-y')) and The time of {Country_Zones [i]} is {country_time. strftime ('H:%M:%S' )¥")
27th Nov 2020, 1:40 AM
Michael Oyegunna
Michael Oyegunna - avatar
+ 1
For practising right indentation use editors which shows space also so you can know where you indent is missing first of all practise on it and then when you think you got the practise of indentation leave that habit and so you will learn to indent how much space you need to give in these codes
27th Nov 2020, 8:45 AM
Sayyam Jain
Sayyam Jain - avatar
+ 1
There is no indentation after the for statements. If pressing enter after a colon doesn't indent the next line, try using tab or a certain number of spaces( 4 spaces is preferable ) and if using spaces, be consistent with the number you're using.
28th Nov 2020, 6:13 AM
Kachi Emmanuel
Kachi Emmanuel - avatar
0
Indentation simply means shifting the line of codes under a control structure to show they are inside that control structure. I.e line 6 after your for statement the next code below the ":" needs a tab
27th Nov 2020, 1:36 AM
Michael Oyegunna
Michael Oyegunna - avatar
0
Indentation means tab (4spaces) space before that loop or if else statement
27th Nov 2020, 2:26 PM
Imran Ali
Imran Ali - avatar