3.11_ jobs

# 1, there is a list of [ 'alex', 49, [ 1900,3,18]], the list of names are removed, age, birth year, month, day assigned to different variables 
show = [ 'alex', 49 , [1900,. 3, 18 is]]
name = Show [0]
Age = Show [. 1]
years = Show [2] [0]
month The = Show [2] [. 1]
Day = Show [2] [2]
Print ( name, Age, years, month the, Day)
# 2, and insert a simulated pop queue list method
info = [0]
info.insert (. 1,. 1)
info.insert (2, 2)
info.insert (. 3,. 3 )
Print (info)
Print (info.pop (0))
Print (info.pop (0))
Print (info.pop (0))
Print (info.pop (0))
# 3. INSERT lists and pop with sIMULATION stack
info = [0]
info.insert (. 1,. 1)
info.insert (2, 2)
info.insert (. 3,. 3)
Print (info)
Print (info.pop (. 3))
Print (info.pop (2))
Print (info.pop (1))
Print (info.pop (0))
# 4, simple shopping cart, requirements are as follows:
# Print the implementation details, the user enters the number of trade names and purchase, it will trade name, price,
# the number of later added in the form of triplets shopping list, if the input is empty or other illegal input require the user to re-enter  
msg_dic = {
'Apple': 10,
'Tesla': 100000,
'MAC': 3000,
'Lenovo' : 30000,
'Chicken': 10,
}
the while True:
# traversing commodity and price
for K, V in msg_dic.items ():
Print ( "trade name:% s, price:% d"% (k, v))
shop = input ( "enter a product name:")
# judge
IF shop.isspace () or not in msg_dic Shop:
Print ( "! mistake, re-enter")
the else:
NUM = the iNPUT ( "enter the number of purchase:")
if num.isdigit ():
num = int (num)
shop_price = msg_dic [Shop] * NUM
shop_tuple = (msg_dic [Shop], NUM, shop_price)
Print ( "shopping list:", shop_tuple)
BREAK
the else:
Print ( "! Please enter the number")
BREAK


# 5, has a set of values as follows [11,22,33,44,55,66,77,88,99,90 ...], all values greater than 66 will be saved to the dictionary
# key in the first one, will be less than the value of 66 is stored to the second the two key values
# namely: { 'k1': all values greater than 66, 'k2': all values less than 66}
Show = [. 11, 22 is, 33 is, 44 is, 55, 66, 77, 88, 99 , 90]
Data = { 'K1': [], 'K2': []}
for I in Show:
IF I> 66:
Data [ 'K1'] the append (I).
elif I <66:
Data [ 'K2 '] .append (I)
Print (Data)

#. 6, statistical s =' hello alex alex say hello sb sb 'The number of each word
s = 'hello alex alex say hello sb sb'
print(len(s))

Guess you like

Origin www.cnblogs.com/zhenghuiwen/p/12465218.html