+ 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?

14th Feb 2021, 3:14 PM
Abhishek Kumar
Abhishek Kumar - avatar
2 ответов
+ 2
Block of code inside a loop or conditional statement must be well indented. if ...: # code else: # code
14th Feb 2021, 3:33 PM
Ipang
+ 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 __________________
14th Feb 2021, 3:36 PM
noteve
noteve - avatar