Python 24-point program

Source: Internet
Author: User


MSO-Hansi-font-family: "Times New Roman" '> today, I am asking for help on the Internet.
7 MSO-Hansi-font-family: "Times New Roman" '> use +-*/"Times New Roman"'> calculate 21.yes"> "Times New Roman "; MSO-Hansi-font-family: "Times New Roman" '> I wrote one myself. MSO-Hansi-font-family: "Times New Roman" '> but the Code cannot be found. "Times New Roman"'> I even know the 24; MSO-ascii-font-family: "Times New Roman "; MSO-Hansi-font-family: "Times New Roman" '> many vertices say that MSO-Hansi-font-family: "Times New Roman" '> so I searched the internet.

MSO-Hansi-font-family: "Times New Roman" '> there are many, "Times New Roman" '> but a (; MSO-ascii-font-family: "Times New Roman "; MSO-Hansi-font-family: "Times New Roman" '> in fact, it cannot be called C ++, MSO-Hansi-font-family: "Times New Roman" '> All C "Times New Roman"'> syntax),; MSO-ascii-font-family: "Times New Roman "; MSO-Hansi-font-family: "Times New Roman" '> tried nmso-Hansi-font-family: "Times New Roman"'> multiple times, BORLANDC3.1 "Times New Roman" '> and GCC; MSO-ascii-font-family: "Times New Roman"; MSO-Hansi-font-family: "Times New Roman" '> cannot be compiled. MSO-Hansi-font-family: "Times New Roman" '> you also found VB, "Times New Roman"'> and web; MSO-ascii-font-family: "Times New Roman"; MSO-Hansi-font-family: "Times New Roman" '>, MSO-Hansi-font-family: "Times New Roman" '> it seems useless. MSO-ascii-font-family: "Times New Roman"; MSO-Hansi-font-family: "Times New Roman" '> when looking for something, MSO-Hansi-font-family: "Times New Roman" '> I figured it out myself. ("Times New Roman" '> how to use this program)

 

MSO-Hansi-font-family: "Times New Roman" '> to avoid such problems in the future, "Times New Roman" '> spent an hour using Python "Times New Roman"'> wrote one by yourself, "Times New Roman" '> or Python "Times New Roman"'> good ~~~~~~~

 

Funs = [Lambda X, item: (x + item [0],

Yes ">
STR (x) + '+ (' + item [1] + ')'

Yes ">
),

Yes "> Lambda X, item: (x-item [0],

Yes ">
STR (x) + '-(' + item [1] + ')'

Yes ">
),

Yes "> Lambda X, item: (item [0]-X,

Yes "> yes"> '(' + item [1] + ')-' + STR (X)

Yes ">
),

Yes "> Lambda X, item: (x * item [0],

Yes ">
STR (x) + '* (' + item [1] + ')'

Yes ">
),

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

 
Yes "> (x/item [0],

Yes ">
STR (x) + '/(' + item [1] + ')'

Yes ">
),

Yes "> Lambda X, item: (x = 0 and (0, 'zzz') or/

Yes ">
(Item [0]/X,

Yes ">
'(' + Item [1] + ')/' + STR (X)

Yes ">
)

]

 

Def Con (Num ):

Yes "> L = Len (Num)

Yes "> P = List ()

Yes "> if l = 1: Return {num [0]: STR (Num [0])}

Yes "> for I in range (l ):

Yes "> for F in funs:

Yes ">
P + = map (lambda item: F (Num [I], item ),

Yes ">
Con (Num [: I] + num [I + 1:]). Items ()

Yes ">
)

Yes "> return dict (P)

 

Print con (MAP (float, [21.0,]). Get (, 0)

 

 

MSO-Hansi-font-family: "Times New Roman" '> I will not explain the code. "Times New Roman"'> ask if you have any questions.

 

MSO-Hansi-font-family: "Times New Roman" '> In addition, due to the error in floating point calculation ,". get (21.0, 0 "" Times New Roman "'> This sentence is not perfect yet." Times New Roman "'> but it is enough to solve this problem, "Times New Roman" '> everyone knows how to improve it.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.