+ 1
Can i assign a numeric value to a variable under if condition in python.
Program: s = 300000 if(s>200000 and s<= 400000): r = 20 else: r=30 x= s*r/100 print(x) Its show error tell me how can i write this program?
2 ответов
+ 2
Block of code inside a loop or conditional statement must be well indented.
if ...:
# code
else:
# code
+ 1
[ Additional Answer ]
Yes, we can assign variable under if condition.
On your example, if the condition is True then the value of r is 20, otherwise 30.
_________________
if(s>200000 and s<= 400000):
r = 20
else:
r = 30
__________________