014day--python operators and job improvements

Source: Internet
Author: User
Tags bitwise

One, operator

% modulo, returns the remainder of the quotient

10/3 3.33333333335

10//3 3 floors Except, take integers, not rounded

A = 3 b = 5 -----> a<b and A==4 or b<10 and a>1

If the condition in front of or is set, then the formula after or is not followed, and the preceding formula is not considered, and the following is directly calculated.

' 123 '. IsDigit () determines whether a string can be converted to a number

Identity judgment:type (123) is int type (' 123 ') is STR

Bit operations:

128 64 32 16 8 4 2 1

a=60 0 0 1 1 1 1 0 0

B=13 0 0 0 0 1 1 0 1

& Bitwise vs . 0 0 0 0 1 1 0 0

| bitwise OR 0 0 1 1 1 1 0 1

second, the Operation

Level three menu (low version)

menu = {    'Beijing':{        'Haidian':{            'Five crossing':{                'Soho':{},                'NetEase':{},                'Google':{}            },            'Zhongguancun':{                'Iqiyi Art':{},                'Autohome':{},                'Youku':{},            },            'on the ground':{                'Baidu':{},            },        },        'changping':{            'Shahe':{                'old boy':{},                'Beihang University':{},            },            'Tin Tong Court':{},            'Huilongguan':{},        },        'Chaoyang':{},        'Dongcheng':{},    },    'Shanghai':{        'Minhang':{            "People's square":{                'Fried Chicken Shop':{}            }        },        'Zhabei':{            'Train Warfare':{                'Ctrip':{}            }        },        'Pudong':{},    },    'Shandong': {},}break_flag=True whileBreak_flag: forIinchMenu:Print(i) Choice1= Input (':'). Strip ()ifLen (Choice1) ==0:Continue    ifchoice1=='Q': Break_flag=FalseContinue    ifChoice1inchMenu: whileBreak_flag: forJinchMenu[choice1]:Print(j) Choice2= Input ('>>:'). Strip ()ifLen (CHOICE2) ==0:Continue            ifchoice2=='b': Break            ifchoice2=='Q': Break_flag=FalseContinue            ifChoice2inchMenu[choice1]: whileBreak_flag: forKinchMenu[choice1][choice2]:Print(k) Choice3= Input ('>>>:'). Strip ()ifLen (choice3) ==0:Continue                    ifchoice3=='b': Break                    ifchoice3=='Q': Break_flag=FalseContinue                    ifChoice3inchMenu[choice1][choice2]: whileBreak_flag: forMinchMenu[choice1][choice2][choice3]:Print(m) Choice4= Input ('>>>>:')                            ifLen (choice4) ==0:Continue                            ifchoice4=='b': Break                            ifchoice4=='Q': Break_flag=FalseContinue
View Code

Shopping Cart optimization operations

Shopping_cart = {}#Shopping CartProduct_list = [                ['iphone', 5800],                ['Xiaomi Phone', 2000],                ['Maotai', 650],                ['Pen', 5],                ['Rice Cooker', 200]]salary= Int (Input ('Input Your Salary:')) whileTrue:index=0 forProductinchproduct_list:Print(index,product) Index+=1Choice= Input ('Please enter product number:')    ifchoice.isdigit (): Choice=int (choice)ifChoice>=0 andchoice<=Len (product_list): Product=Product_list[choice]ifPRODUCT[1] <=Salary:ifPRODUCT[0]inchshopping_cart:shopping_cart[product[1]]+=1Else: shopping_cart[product[0]]=[product[1],1] Salary-=product[1]                Print('The shopping cart has been added:'+product[0]+', your balance is:'+Str (salary))Else:                Print("salary is not enough, the price of the product is:%s, bad:%s"% (str (product[1]), product[1]-salary)) Else:            Print('number does not exist, please re-enter')    elifchoice=='Q':        Print('-----------you have purchased the following items-----------') Id_count= 1Total_cost=0Print('ID Product Unit Price quantity Total Price')         forKeyinchShopping_cart:Print("%s\t\t%s\t\t%s\t\t%s\t\t%s"%(Id_count, Key, Shopping_cart[key][0], shopping_cart[key][1], shopping_cart[key][0]*shopping_cart[key][1])) Id_count+=1Total_cost+=shopping_cart[key][0]*shopping_cart[key][1]        Print('your total cost is:%s'%total_cost)Print('your balance is:%s'%salary)Print('----------------End---------------')    Else:        Print('Number input Error')
View Code

  

014day--python operators and job improvements

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.