0
I am a beginner in python, Please tell me the error in this code.
I have tried a conditional statement, but the following code shows a syntax error in it. I have tried but every time it display the same message about error in the line 2. Please, elaborate. https://code.sololearn.com/ckJ4LWoYEQIA/?ref=app
13 Respostas
+ 2
No, else is required, or you can use another if
+ 1
There should be ":" after "x<10".
But I guess there will be another problem that doesn't cause an error:
When x is smaller than 10, the program will print both "it's working" and "it's not working"
To prevent this, you should change the code to this:
if x<10:
print('its working')
else:
print('its not working')
+ 1
ÎM!N and you really think someone would exit the whole program just not to print something ?
0
if statement is always follower by :
So:
if x<10:
#your code here
0
Yeah, I wanted to print only one of them...
0
Can we print one of them without 'else'.......
0
Thank you.....man.....problem solved.....
0
Yw
0
Yes, there are some solutions if you don't want to use else. But using else is better. One of them is to exit and end the program in the first if statement:
if x<10:
print('its working')
exit()
print('its not working')
Another way is to use another if or elif as Aymane Boukrouh said.
0
Aymane Boukrouh You're right it can't be a good solution to use if the code is more complex
- 1
x=7
if x<10:
print('its working')
else:
print('its not working')