+ 7
is there any mistke in this code
x=5 if x==4: print ("yesss") else : print ("noo")
39 Réponses
+ 22
You have to care about indentation when you're using if-else statement
x=5
if x==4:
print ("yesss")
else :
print ("noo")
Edit:
Check it out for reference.
https://code.sololearn.com/cT5BRIbkia21/?ref=app
You can compare my code with your code to understand it clearly
+ 14
tnx
+ 9
There is no indentation python interpretor will give you an error
+ 5
A space " "
x = 2
if x == 2:
print(x)
else:
print(x +1)
Here in this case the output must be 2 but the output will be
2
3
Because there is not gap in the else part like I have in the if part.
That means that will execute even if the condition is true because it is not the part of the else statement.
You need a space before starting a new line for function, loop, conditions in python for the.
+ 5
x = 5
if x==4:
print("yesss")
else:
print("noo")
+ 4
Usman Muhammed this is the wrong place for advertising. use any advertising thread for this
+ 3
Indentation mistake
+ 3
Actually the code runs , it does exactly what i want.
The indentation is fine if u taka a closer look...
Am just trying to use a function to get an output as that..
Like
def number_type(number):
👆
Something like that
+ 2
Lisa Sanal Yes, the courses are free
+ 2
kk
+ 2
Your code doesn't have indentation for the if statements, therefore you will get an error.
+ 2
This tells the number_type a user inputs
Tells if its a prime number, odd number or even number.
But i am finding it hard to use functions to get the same output.
Number = int(input("enter number: "))
if Number % 2 == 0:
print("Its an even number")
elif Number % 2 != 0:
print("Its an odd number")
elif Number % 2 != 0 and Number % Number == 0 and Number % 3 != 0:
print("its a prime number")
+ 2
When you have : in one program , then next lines must have tab .
This time you have if . If have : and you must write
If x==4:
print("yessss")
else :
print("noo")
+ 2
I think that's right
+ 2
Lisa Sanal Since your question has been answered sufficiently it would be nice if you could mark it as such to avoid more redundant posts. ;)
+ 1
Yes you are correct. There uses curly brackets {} for the statement inside the loop
+ 1
If you write this code on an IDE, it will automatically add indentation to it. But you wrote it here without adding indentation. Nothing else is wrong
+ 1
Lisa Sanal
There is a minor mistake. You must use indentation properly to make this code work.
It should be like this--
x =5
If x==4:
print ("yesss")
else:
print("noo")
Just an additional piece of advice, when you make such syntactical mistakes, Python gives you an error msg. Please read them carefully and you will learn to correct them on your own.
+ 1
He gives noo
Why x not is equal of 4
+ 1
indentation is very important and keep that in mind using tabs and spaces together will cause problem