+ 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
17 ответов
+ 4
https://code.sololearn.com/cLQHVj0tmuC9/#py
+ 3
In python, to tell a line is inside a scope, you have to indent (tab) that line
+ 3
Ok, wait a minute
+ 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
+ 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
+ 2
There is no indentation at all!
+ 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.
+ 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
+ 2
Thank you guys
+ 1
I still didn't understand can you please post the code by correcting it 🙏🙏🙏
+ 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' )¥")
+ 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
+ 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.
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
0
Indentation means tab (4spaces) space before that loop or if else statement