Python's calculation 24 points

xiaoxiao2021-03-06  151

Rel = Original-file href = "Document% 201">

REL = file-list href = "./ Document% 201.files / fileList.xml">

Today, I'm coming to ask for 1 5 6 7 - * / calculated 21. I have written one, but the code can't find it. I know that there are many programs at 24 o'clock, so I have searched it online.

There is a lot of, but one with C (in fact, it can't be called C , all C's grammar), tried N times, BorlandC3.1 and GCCs can't compile. I also found VB, and Web It seems that it is useless. When I found something, I was going to count my head, I even had myself to count myself. (How to calculate this program)

In order to have troubled by this problem, spend an hour to write one with Python itself, or Python is good ~~~~~~~

FUNS = [Lambda X, Item: (x item [0],

Str (x) ' (' item [1] ')'

),

Lambda X, Item: (X-item [0],

Str (x) '- (' item [1] ')'

),

Lambda X, Item: (item [0] -x,

'(' item [1] ') -' STR (x)

),

Lambda X, Item: (x * item [0],

STR (x) '* (' item [1] ')'

),

Lambda X, Item: (item [0] == 0 and (0, 'zzz')) or /

(x / item [0],

Str (x) '/ (' item [1] ')'

),

Lambda X, Item: (x == 0 and (0, 'zzz')) or /

(item [0] / x,

'(' item [1] ') /' STR (x)

)

]

DEF Con (NUM):

L = LEN (NUM)

P = List ()

IF L == 1: Return {Num [0]: Str (Num [0])}

For i in range (L):

For f in funs:

P = MAP (Lambda Item: F (Num [i], item),

Con (NUM [: i] NUM [i 1:]). items ()

)

Return Dict (P)

Print Con (Map (Float, [1, 5, 6, 7])). GET (21.0, 0)

I will not explain the code. If you have any questions, ask.

In addition, due to the error problem of floating point calculations, ". Get (21.0, 0" is not very perfect, but solving this problem is enough, how can I know how everyone knows.

转载请注明原文地址:https://www.9cbs.com/read-127746.html

New Post(0)