Project 9 indentation error

actually i have solved indentation error but its one syntax error here


can u help me in this?

Your if statement is not under the error handling try condition.

Must be under that for the code to work.

Same as the tabs and spaces problem. Shift the whole If condition one step to the right.

@harshitakha925thank u!

1 Like

@swastishree10 I think your code is running now

also as per your last image, your if statement should be under try condition ,
And your try , except , time , should be at same indentation.

just let me know if any other problem :))

@harshitakha925 indentation issue is not there now its showing a syntax error.

@swastishree10 in the above shared code the if block is at the same indentation level as that of try block. But it should be a level inner (deep) than the try block. The try and except block should be at the same identation level.

As you must have know after going through the training content that the LM35 sensor value is divided by 10.24 to get the correct temperature value. So I am sharing my customized code, hope it will clear your doubts.


Hope it solves your problem :slight_smile:

1 Like

yes there is a error because you if statement is same indented as (try,except,time)
to correct it press a spacebar before if
this will help

you can also see a arrow on if when its showing error… the arrow is because of that only

@swastishree10

also have attached ss for refrence :))

1 Like

@harshitakha925 See the print function is at the correct indentation level. Now see that if block is a space behind the correct indentation that is why the error is coming.

At last the sleep function should be executed at the end of while loop ( so it should be a level deeper than the while loop ) but you have assigned wrong indentation to that also.

@swastishree10 I have pasted the correct indented code above. Go through that and I hope you will fund it useful

1 Like

@vishalvats2000 you are correct about the if indentation

sleep function is under while loop, as will put the program to sleep once every loop iteration. so it is indented deeper than while loop.
the (try, except, time) all three should be indented at same level ,
so my ss is error free, and well executed :))

try:
(gap)if sensor_value…

this gap tells that if is under the try condition. And is called indented under try.

SO, in your program, if statement is in the very beginning of the line, without any gap. That is why the whole if condition is not running.

This indentation will be visible to you in an IDE.
Use the desktop environment version of ubuntu, to be free of this chaos.

i did it still the same error in if statement syntax error is showing.
also i want to know how your tabs are working perfectly and how to copy and paste here?

Yes i did but still the same error.

1 Like

Actually, when you’re typing the code, and you reach try: or if statement: conditions, in the end of that line after reaching ’ : ’ you have to press enter. That will automatically do the correct indentation. If you manually put the cursor down and use space and tabs, you get higher chance of error.

yes i also used it ie to press enter after the conditions, but that also not giving me the correct output

Is your cursor moving a bit ahead from the panel or is it in the very beginning of the left panel of window.

I too did the same as yours but still the error in syntax in IF statement…its very hectic for me to again n again write whole code can u tell me how to copy n paste here in ubuntu?

Very beginning of panel

now my code is running…can u tell me how to stop it from running?

Press Ctrl+C to stop it