Thank you I will take a look.
I will clarify what I meant if this does not solve the issue.
I get a "KeyError" every time that "halogen" or "acceptor" is put inside of the arguments. Perhaps my failed code would be a better way to illustrate what I am speaking of . . .
I know loops are involved in here but I am struggling to create one correctly.
Thanks for your time!
Sorry, I made a mistake...
I meant " I get a "KeyError" every time a "halogen" or "acceptor" is put inside of the arguments that is not listed in x or y. Perhaps my failed code would be a better way to illustrate what I am speaking of . . ."
I will clarify what I meant if this does not solve the issue.
x = {"F": "Fluorine", "Cl": "Chlorine"} y = {"O": "Oxygen"} def hal(a): for halogens in x: if halogens == a: print(x[a]) return(x[a]) def acc(b): for acceptors in y: if acceptors == b: print(y[b]) return y[b] def is_halogen_bond(halogen, acceptor ): hal(a) acc(b) is_halogen_bond("F", "O")On the code that I have I want is
is_halogen_bond("F", "O")to print Fluorine and Oxygen, which it does.
I get a "KeyError" every time that "halogen" or "acceptor" is put inside of the arguments. Perhaps my failed code would be a better way to illustrate what I am speaking of . . .
Error:Traceback (most recent call last):
File "halogen.py", line 24, in <module>
is_halogen_bond("B", "O")
File "halogen.py", line 21, in is_halogen_bond
hal(halogen)
File "halogen.py", line 8, in hal
return(x[a])
KeyError: 'B'
To resolve this issue I attempted a while loop and all loops under the sun and I failed. What I want my code to do from this point is then print something like this if the halogen argument produces a key error: print("Error, not a halogen.")and then prompt the user to enter a halogen that is in the list x. I want the same to apply for acceptors with the list y.
I know loops are involved in here but I am struggling to create one correctly.
Thanks for your time!
Sorry, I made a mistake...
I meant " I get a "KeyError" every time a "halogen" or "acceptor" is put inside of the arguments that is not listed in x or y. Perhaps my failed code would be a better way to illustrate what I am speaking of . . ."