程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python daily practice (new question bank on Niuke) -- day 10: 40 tips from introduction to practice

編輯:Python

List of articles

  • 1. send out offer
  • 2. Party list
  • 3. The CV
  • 4. Sorting and inversion
  • 5. Count to 20
  • 6. How to make question brushing more efficient ?

Preface

Recently, many kids who have learned the basics asked me how to improve my programming level ? What should I do after learning the basics ? Mingming learned a lot , Do the project but don't know how to get started , In fact, this is too little practice , Only pay attention to learning , But ignore the question , Only continuous practice can improve and consolidate programming thinking and ability !



I happened to see that niuke.com has recently released Python So I had a good experience with my new question bank



Link address : Cattle from | Python From introduction to practice , Stop talking nonsense and speed up , Or follow the questions below !!!

1. send out offer

describe : After the interview, a company , Creates a string that contains the string in turn ‘Allen’ and ‘Tom’ A list of offer_list, As a list of people who have passed the interview .
Please send similar messages to the names in the list in turn ‘Allen, you have passed our interview and will soon become a member of our company.’ Sentences .
But because of Tom There are other options , No confirmation of this offer,HR Select the one that can just confirm this offer Of Andy, So please put the list offer_list in ‘Tom’ Change your name to ‘Andy’ ,
Then send similar messages in sequence ‘Andy, welcome to join us!’ Sentences .

Input description : nothing

Output description : Output according to the title description .
Allen, you have passed our interview and will soon become a member of our company.
Tom, you have passed our interview and will soon become a member of our company.
Allen, welcome to join us!
Andy, welcome to join us!

Implementation code :

offer_list = ['Allen', 'Tom']
# out
for i in range(len(offer_list)):
print('{}, you have passed our interview and will soon become a member of our company.'.format(offer_list[i]))
for str_i in offer_list:
if str_i == 'Tom':
print('Andy, welcome to join us!')
else:
print('{}, welcome to join us!'.format(str_i))

Running results :

Allen, you have passed our interview and will soon become a member of our company.
Tom, you have passed our interview and will soon become a member of our company.
Allen, welcome to join us!
Andy, welcome to join us!

2. Party list

describe : To celebrate that tuoruichi has found a suitable partner in Niuai , So tuoruichi created a string that contains the string in turn ‘Niuniu’ and ‘Niu Ke Le’ A list of guest_list, As an invitation list for the celebration party .
Please send similar messages to the names in the list in turn ’Niuniu, do you want to come to my celebration party?' Sentences .
Tuoruichi's good friend Niuniu 、GURR Brother and LOLO Sister is also free , So please use insert() Method takes the string ’GURR’ Insert into list guest_list The beginning of ,
Reuse insert() Method takes the string ’Niumei’ Insert into string ’Niu Ke Le’ In front of , Reuse append() Method takes the string ’LOLO’ Insert into list guest_list Last ,
Then send similar messages in sequence ’Niuniu, thank you for coming to my celebration party!' Sentences .

Input description : nothing

Output description : Output according to the title description ( Note that the front and back output parts should be separated by a blank line ).
Niuniu, do you want to come to my celebration party?
Niu Ke Le, do you want to come to my celebration party?

GURR, thank you for coming to my celebration party!
Niuniu, thank you for coming to my celebration party!
Niumei, thank you for coming to my celebration party!
Niu Ke Le, thank you for coming to my celebration party!
LOLO, thank you for coming to my celebration party!

Implementation code :

guest_list = ['Niuniu', 'Niu Ke Le']
for i in guest_list:
print('%s, do you want to come to my celebration party?' % i)
print()
guest_list.insert(0, 'GURR')
guest_list.insert(2, 'Niumei')
guest_list.append('LOLO')
for j in guest_list:
print('%s, thank you for coming to my celebration party!' % j)

Running results :

Niuniu, do you want to come to my celebration party?
Niu Ke Le, do you want to come to my celebration party?
GURR, thank you for coming to my celebration party!
Niuniu, thank you for coming to my celebration party!
Niumei, thank you for coming to my celebration party!
Niu Ke Le, thank you for coming to my celebration party!
LOLO, thank you for coming to my celebration party!

3. The CV

describe : Graduation season is here , Niuniu has prepared her resume in order to find a job , And a list of delivery companies company_list, This includes strings ‘Alibaba’, ‘Baidu’, ‘Tencent’, ‘MeiTuan’, ‘JD’ As the target company for him to send his resume .
Please send a message to each company in the list similar to ‘Hello Alibaba, here is my resume!’.
However , Unfortunately Alibaba、Tencent、MeiTuan、JD None of them passed Niuniu's resume review , Only Baidu Replied to him , Invite him to an interview . So you need to :
Use del() Function to delete the list company_list String in ‘Alibaba’.
Use pop() Function to delete the list in turn company_list String in ’JD’,‘MeiTuan’.
Use remove() Function to delete the list company_list String in ’Tencent’.
Finally, send a similar message to the remaining companies in the list ‘Baidu, thank you for passing my resume. I will attend the interview on time!’ The news of .

Input description : nothing

Output description : Output according to the title description ( Note that the front and back output parts should be separated by a blank line ).
Hello Alibaba, here is my resume!
Hello Baidu, here is my resume!
Hello Tencent, here is my resume!
Hello MeiTuan, here is my resume!
Hello JD, here is my resume!

Baidu, thank you for passing my resume. I will attend the interview on time!

Implementation code :

company_list = ['Alibaba', 'Baidu', 'Tencent', 'MeiTuan', 'JD']
for i in company_list:
print('Hello %s, here is my resume!' % i)
del company_list[0]
company_list.pop()
company_list.pop()
company_list.remove('Tencent')
print()
for j in company_list:
print('%s, thank you for passing my resume. I will attend the interview on time!' % j)

Running results :

Hello Alibaba, here is my resume!
Hello Baidu, here is my resume!
Hello Tencent, here is my resume!
Hello MeiTuan, here is my resume!
Hello JD, here is my resume!
Baidu, thank you for passing my resume. I will attend the interview on time!

4. Sorting and inversion

describe : Create a string that contains the string in turn ’P’、‘y’、‘t’、‘h’、‘o’ and ’n’ A list of my_list after ,
First use print() Statement to print a string line by line ’Here is the original list:’, Use it directly print() Statement to the list just created my_list Print out the whole ,

Output a newline , Reuse print() Statement to print a string line by line ’The result of a temporary reverse order:’,
Reuse print() The statement uses sorted() Function to list my_list The results of temporary descending sorting are printed out ;

Output a newline , Reuse print() Statement to print a string line by line ’Here is the original list again:’,
Reuse print() Statement to the original list my_list Print out the whole , Confirm that the original list has not been changed my_list;

On the list my_list call sort() Method , Make list my_list The strings in are sorted in descending order ,
Output a newline , Reuse print() Statement to print a string line by line ’The list was changed to:’,
Reuse print() Statement to change the modified list my_list Print out the whole , Confirmation list my_list The strings of are sorted in descending order ;

On the list my_list call reverse() Method , Make list my_list The position of the string in is flipped back and forth ,
Output a newline , Reuse print() Statement to print a string line by line ’The list was changed to:’,
Reuse print() Statement to change the modified list my_list Print out the whole , Confirmation list my_list The position of the string is flipped back and forth .

Input description : nothing

Output description : Output according to the title description ( Note that the front and back output parts should be separated by a blank line ).
Here is the original list:
[‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]

The result of a temporary reverse order:
[‘y’, ‘t’, ‘o’, ‘n’, ‘h’, ‘P’]

Here is the original list again:
[‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]

The list was changed to:
[‘y’, ‘t’, ‘o’, ‘n’, ‘h’, ‘P’]

The list was changed to:
[‘P’, ‘h’, ‘n’, ‘o’, ‘t’, ‘y’]

Code implementation :

def func():
my_list = ['P', 'y', 't', 'h', 'o', 'n']
print('Here is the original list:')
print(my_list)
print('') # Output line feed 
print('The result of a temporary reverse order:')
print(sorted(my_list, reverse=True)) # The output is sorted in positive order at the same time , At the same time, we are reversing , That is, reverse order ( The original list has not changed )
print('')
print('Here is the original list again:')
print(my_list)
print('')
my_list.sort(reverse=True) # null , At the same time reverse , That is, ascending sort ( This is the whole list changed )
print('The list was changed to:')
print(my_list)
print('')
my_list.reverse()
print('The list was changed to:')
print(my_list)
func()

Running results :

Here is the original list:
['P', 'y', 't', 'h', 'o', 'n']
The result of a temporary reverse order:
['y', 't', 'o', 'n', 'h', 'P']
Here is the original list again:
['P', 'y', 't', 'h', 'o', 'n']
The list was changed to:
['y', 't', 'o', 'n', 'h', 'P']
The list was changed to:
['P', 'h', 'n', 'o', 't', 'y']

5. Count to 20

describe : Use one for loop or while loop Print [1, 20] All integers in ( One number per line ).

Input description : nothing

Output description : Output according to the title description .

Implementation code :

for i in range(1, 21):
print(i)

Running results :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

6. How to make question brushing more efficient ?

Niuke, a little partner who dislikes the blogger's slow update, brushes the questions by himself



Link address : Cattle from | Python From introduction to practice , Stop talking nonsense and speed up !!!


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved