Error when trying to apply a conditional statement to sympy

Описание к видео Error when trying to apply a conditional statement to sympy

Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram:   / ky.emrah  

Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Error when trying to apply a conditional statement to sympy

I'm trying to set a conditional statmeent in sympy so that when the iterable is not equal to a certain number (30) in this case, it returns 0.
My code is:
def formula(address):

address0 = 30
logic = 3 * x

Define the symbol and the summation range
x = symbols('x')

expr = Piecewise(
(x + logic, logic == address0), # When x equals certain_integer, only add logic
((x + logic) - (x + logic), logic!=address0) # For all other values of x, apply full logic (x + logic - x + logic)
)

#If -x + logic only do it to the ones that aren't address0
total = summation(expr(x, 0, 089237316195423570985008687907836))
total2 = total - address0
print(f'{total}\n{total2}')
return total2

def formula(address):

address0 = 30
logic = 3 * x

Define the symbol and the summation range
x = symbols('x')

expr = Piecewise(
(x + logic, logic == address0), # When x equals certain_integer, only add logic
((x + logic) - (x + logic), logic!=address0) # For all other values of x, apply full logic (x + logic - x + logic)
)

#If -x + logic only do it to the ones that aren't address0
total = summation(expr(x, 0, 089237316195423570985008687907836))
total2 = total - address0
print(f'{total}\n{total2}')
return total2

As you can see in my code, in the expr variable I set x+logic when logic is 30 and when the other logicsaren't 30 it returns 0 since it subtracts it. The code is returning 0 regardless of what I do and I don't know why. Can someone help me?


Tags: python,python-3.x,sympySource of the question:
https://stackoverflow.com/questions/7...

Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/

Комментарии

Информация по комментариям в разработке