0

Thank millions for sharing and caring!

I need to create and use symbols in dynamic way. In fact, symbols are made based on user input and used in code so I must use f'strings to make them. As shown below:

L= ['xCl', 'xNa']
for j in range(len(L)):
     locals()[L[j]] = sympy.symbols(L[j])

i = 'Na'
j  = 'Cl' 
gg = f"x{i}" * f"x{j}"
print('gg:', gg)

But I received the following error:

TypeError: can't multiply sequence by non-int of type 'Symbol'

While I need to have: gg = xCl * xNaCl Could possibly let me know how can do it.

Z. K
  • 7
  • 4

1 Answers1

0

This way my issue has gone:

    for j in range(len(L)):
    locals()[L[j]] = sp.symbols(L[j])
   
i = 'Na'
j = 'Cl'
g =sp.symbols(f'x{i}') * sp.symbols(f'x{j}')
type(g)
print('g:', g)
Z. K
  • 7
  • 4