Friday, 27 September 2013

Can't identify syntax error? Also, need using raw_input with list

Can't identify syntax error? Also, need using raw_input with list

I'm trying to develop a simple Python program to calculate the formula
mass of a compound. I'm facing 2 issues:
There's apparently a syntax error with 'b' but I don't know what it is.
Here is what I've done so far:
def FormulaMass():
H = 1
He = 4
Li = 7
Be = 9
B = 11
C = 12
N = 14
O = 16
F = 19
Ne = 20
Na = 23
Mg = 24
Al = 27
Si = 28
P = 31
S = 32
Cl = 35.5
Ar = 40
K = 39
Ca = 40
Sc = 45
Ti = 48
V = 51
Cr = 52
Mn = 55
Fe = 56
Co = 59
Ni = 59
Cu = 63.5
Zn = 65
Ga = 70
Ge = 73
As = 75
Se = 79
Br = 80
Rb = 85.5
Sr = 88
Y = 89
Zr = 91
Nb = 93
Mo = 96
Tc = 98
Ru = 101
Rh = 103
Pd = 106.5
Ag = 108
Cd = 112.5
In = 115
Sn = 119
Sb = 122
Te = 128
I =127
Xe = 131
Cs = 133
Ba = 137
La = 139
Ce = 140
Pr = 141
Nd = 144
Pm = 145
Sm = 150
Eu = 152
Gd = 157
Tb = 159
Dy = 162.5
Ho = 165
Er = 167
Tm = 169
Yb = 173
Lu = 175
Hf = 178.5
Ta = 181
W = 184
Re = 186
Os = 190
Ir = 192
Pt = 195
Au = 197
Hg = 201
Tl = 204
Pb = 207
Bi = 209
Po = 209
At = 210
Rn = 222
Fr = 223
Ra = 226
Ac = 227
Th = 232
Pa = 231
U = 238
Np = 237
Pu = 244
Am = 243
Cm = 247
Bk = 247
Cf = 251
Es = 252
Fm = 257
Md = 258
No = 259
Rf = 261
Db = 262
Sg = 266
Bh = 264
Hs = 277
Mt = 268
Ds = 271
Rg = 272
Uub = 285
Uut = 284
Uuq = 289
Uup = 288
Uuh = 292
Uuo = 294
element = [H, He, Li, Be, B. C, N, O, F, Ne, Na, Mg, Al, Si, P, S, Cl,
Ar, K, Ca, Sc, Ti, V, Cr, Mn, Fe, Co, Ni, Cu, Zn, Ga, Ge, As, Se, Br,
Rb, Sr, Y, Zr, Nb, Mo, Tc, Ru, Rh, Pd, Ag, Cd, In, Sn, Sb, Te, I, Xe,
Cs, Ba, La, Ce, Pr, Nd, Pm, Sm, Eu, Gd, Tb, Dy, Ho, Er, Tm, Yb, Lu,
Hf, Ta, W, Re, Os, Ir, Pt, Au, Hg, Tl, Pb, Bi, Po, At, Rn, Fr, Ra, Ac,
Th, Pa, U, Np, Pu, Am, Cm, Bk, Cf, Es, Fm, Md, No, Rf, Db, Sg, Bh, Hs,
Mt, Ds, Rg, Uub, Uut, Uuq, Uup, Uuh, Uuo]
a = raw_input('Which' + str(element) + '?')
b = float(raw_input('How many moles?'))
c = str(raw_input('Is that all [Y/N]?'))
while c == 'N':
print
'a' doesn't actually come up when running the code it just immediately
identifies this syntax error in 'b'.
What I'm trying to do with 'a' is to allow the user to input a constant
from the list 'element' so that the mass (depending on the number of moles
can be calculated). Now one potential problem I see is that I'm not sure
how to allow users to input different elements with different numbers of
moles without creating endless constants (e.g. a, b ,c...).
The aim is to add a*b at the end to find the mass but is there a way to
make multiple a's and b's so in theory users could have a*b + a1*b1...
PS Sorry for not putting in my code properly it would take too long for me
to put 4 indents after each line :/

No comments:

Post a Comment