variable creation

Jon jspeis at gmail.com
Tue Aug 8 10:46:20 EDT 2006


Hi,
I'm not sure if this is exactly what you had in mind but what about
something like this:

elements = []
Els = ""
pt = {'H': 1.00794, 'He': 4.002602, 'Li': 6.941, 'Be': 9.012182,
'B':10.811}
while Els != 'No':
    Els = raw_input("""Are there any further elements you would like to
include? if so type the element, eg, Pd. If not type No:""")
    if pt.has_key(Els):
        elements.append({Els:pt[Els]})

print elements


Alistair King wrote:
> Hei all,
>
> im trying to create a list of variables for further use:
>
>
> Els = raw_input("Are there any further elements you would like to
> include? if so type the element, eg, Pd. If not type No: ")
>
>     if Els != 'No':
>         el = Els in pt
>         while el == 1 and Els != 'Next':
>             elements = []
>             elements.insert(-1, Els)
>
>             Els = raw_input("Which further element would you like to
> include, eg, Pd, if not type Next: ")
>             el = Els in pt
>
>             while el == 0 and Els != 'Next':
>                 Els = raw_input("This is not an element in the periodic
> table, please try again, eg Pd, If you dont wish to include any more,
> type Next: ")
>                 if el == 1:
>                     elements.insert(-1, Els)
>
>         while el == 0:
>             Els = raw_input("This is not an element in the periodic
> table, please try again, eg Pd. If you dont wish to include any more,
> type Next: ")
>
>     print elements
>
>
> this works to a certain extent but gets stuck on some loop. Im a
> beginner and am not sure where im going wrong.
>
> here is a portion of the dictionary containing typical elements:
>
> pt = {'H': 1.00794, 'He': 4.002602, 'Li': 6.941, 'Be': 9.012182, 'B':
> 10.811}
>
>
> Ali
>
>
> --
> Dr. Alistair King
> Research Chemist,
> Laboratory of Organic Chemistry,
> Department of Chemistry,
> Faculty of Science
> P.O. Box 55 (A.I. Virtasen aukio 1)
> FIN-00014 University of Helsinki
> Tel. +358 9 191 50429, Mobile +358 (0)50 5279446
> Fax +358 9 191 50366




More information about the Python-list mailing list