Python Forum
Error : "can't multiply sequence by non-int of type 'float' "
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error : "can't multiply sequence by non-int of type 'float' "
#1
Hello ! Please can someone help me to resolve this error, this is the One-electron approximate form. I need to applicate this equation for all orbitals of the atoms Cadmium, Thelium and Zinc (CdTeZn). I have the orbitals number of each atom and the corresponding J, as well as the number of electrons in each orbital.

from math import exp

# Approximate one-electron profiles :
    
# Zinc Zn, atomic number = 30
# Electronic Configuration : 1s2  2s2  2p6  3s2  3p6  4s2  3d10

# Cademium Cd, atomic number = 48
# Electronic Configuration : 1s2  2s2  2p6  3s2  3p6  4s2  3d10  4p6  5s2  4d10

# Thelium Te, atomic number = 52
# Electronic Configuration : 1s2  2s2  2p6  3s2  3p6  4s2  3d10  4p6  5s2  4d10  5s2  5p4

# For Zn
n = 2
d1 = (n - 1 / n) ** 1/n
d2 = 2/n * [d1** (1-n)]
# Ji,0 = Ji (0) <=> la valeur du profil à Pz = 0
J1_30 = 2.90*10**-2  # J(i = 1s), Pz = 30   ;    
Pz = 30
# electrons number = 1

# General equation form
# Ji,A_Pz = Ji,0* ((n * d2/2) [(d1 + d2 * Ji,0 * abs(Pz)) ** (n-1)]) (exp [d1**n- ((d1 + d2 * Ji,0 * abs(Pz))**n)])

Ji,A_Pz = J1_30 * ((n * d2/2) [(d1 + d2 * J1_30 * abs(Pz)) ** (n-1)]) (exp [d1**n- ((d1 + d2 * J1_30 * abs(Pz))**n)])
Error:
TypeError: can't multiply sequence by non-int of type 'float'
Larz60+ write Apr-12-2021, 04:55 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Also, when posting error traceback, please post entire, unaltered traceback.
Reply
#2
This is a float number (likely):
2/n
This is a list (list is a sequence type):
[d1** (1-n)]
You cannot multiply a list by a float number. You can multiple a list by an integer, but that results in a larger list with repeats.
[3]*3 == [3, 3, 3]
Most likely I think you are using square brackets when you should be using parenthesis. This code works fine.
d2 = 2/n * (d1** (1-n))
Look through your equations and make sure you are using the correct punctuation. Aside from square brackets where there should be parenthesis I think you are missing some implied operators (missing *).
Ala likes this post
Reply
#3
Error:
Traceback (most recent call last):

File "C:\Users\AA266201\.spyder-py3\temp.py", line 33, in <module>
Ji,A_Pz =(( J1_30) * ((n * d2/2) [(d1 + d2 *( J1_30) * abs(Pz)) ** (n-1)])) (exp [d1**n- ((d1 + d2 *( J1_30) * abs(Pz))**n)])

TypeError: 'float' object is not subscriptable

from math import exp
# Zinc Zn, Numéro atomique = 30
# Configuration électronique : 1s2  2s2  2p6  3s2  3p6  4s2  3d10

# Cademium Cd, Numéro atomique = 48
# Configuration électronique : 1s2  2s2  2p6  3s2  3p6  4s2  3d10  4p6  5s2  4d10

# Thelium Te, Numéro atomique = 52
# Configuration électronique : 1s2  2s2  2p6  3s2  3p6  4s2  3d10  4p6  5s2  4d10  5s2  5p4
# Approximate one-electron profiles :
# For Zn
n = 2
d1 = (n - 1 / n) ** 1/n
d2 = 2/n * (d1** (1-n))[python]
[python]# Ji,0 = Ji (0) <=> la valeur du profil à Pz = 0
J1_30 = 2.90*10**-2
   # J(i = 1s), Pz = 30   ; 
Pz = 30
# Nombre d'électrons = 1

# General equation form
# Ji,A_Pz = Ji,0* ((n * d2/2) [(d1 + d2 * Ji,0 * abs(Pz)) ** (n-1)]) (exp [d1**n- ((d1 + d2 * Ji,0 * abs(Pz))**n)])
Ji,A_Pz = (J1_30) * ((n * d2/2) [(d1 + d2 *( J1_30) * abs(Pz)) ** (n-1)]) (exp [d1**n- ((d1 + d2 *( J1_30) * abs(Pz))**n)])
Reply
#4
Same problem, different message. You should not be using square brackets. Square brackets are used for creating lists or indexing sequence types. You are doing niether.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Wrong type error rowan_bradley 6 1,146 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  Type Error: Unsupported Operand jhancock 2 1,068 Jul-22-2023, 11:33 PM
Last Post: jhancock
  Write Null values as 0.0 (float) type in csv mg24 3 1,312 Dec-07-2022, 09:04 PM
Last Post: deanhystad
  Python Anytree - Is not of type 'NodeMixin' error georgebijum 3 2,027 May-05-2022, 01:43 PM
Last Post: Gribouillis
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,028 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  Getting error trying to use functions to multiply numbers rrowhe4d 5 1,837 Aug-30-2021, 07:11 AM
Last Post: Yoriz
  Why can't I explicitly call __bool__() on sequence type? quazirfan 11 4,541 Aug-20-2021, 06:49 AM
Last Post: Gribouillis
  Incorrect Type Error milkycow 4 2,828 Jun-25-2021, 06:04 AM
Last Post: milkycow
Star Type Error: 'in' object is not callable nman52 3 3,328 May-01-2021, 11:03 PM
Last Post: nman52
  Type Error in Python MarcusB 3 2,527 Mar-30-2021, 06:34 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020