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 !!!
describe : Niuniu has one name = [‘Niumei’, ‘YOLO’, ‘Niu Ke Le’, ‘Mona’] Recorded the names of his best friends , Please create a two-dimensional list friends, Use append Function will name Add to friends The first line of .
If Niumei I like to eat pizza, Favorite numbers 3,YOLO I like to eat fish, Favorite numbers 6,Niu Ke Le I like to eat potato, Favorite numbers 0,Mona I like to eat beef, Favorite numbers 3.
Please create a list again food Record your friends' favorite foods in turn , And use the created list append Function added to friends The second line of ;
And then create a list number Record your friends' favorite colors in turn , And use the created list append Function added to friends The third line of .
such friends Is a two-dimensional list, Use print Function to print the two-dimensional directly list.
Input description : nothing
Output description :[[‘Niumei’, ‘YOLO’, ‘Niu Ke Le’, ‘Mona’], [‘pizza’, ‘fish’, ‘potato’, ‘beef’], [3, 6, 0, 3]]
Implementation code :
name = ['Niumei', 'YOLO', 'Niu Ke Le', 'Mona']
meul = ['pizza', 'fish', 'potato', 'beef']
number = [3, 6, 0, 3]
friends = []
friends.append(name)
friends.append(meul)
friends.append(number)
print(friends)
Running results :
[['Niumei', 'YOLO', 'Niu Ke Le', 'Mona'], ['pizza', 'fish', 'potato', 'beef'], [3, 6, 0, 3]]
describe : Create a string that contains the string in turn ’P’、‘y’、‘t’、‘h’、‘o’ and ’n’ A list of my_list,
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 number that my_list has is:’,
Reuse len() Function to get the list my_list How many strings are there , And use print() Function to print the integer line by line .
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 number that my_list has is:
6
Implementation code :
my_list = ['P', 'y', 't', 'h', 'o', 'n']
print('Here is the original list:')
print(my_list)
print()
print('The number that my_list has is:')
print(len(my_list))
Running results :
Here is the original list:
['P', 'y', 't', 'h', 'o', 'n']
The number that my_list has is:
6
describe : Niu Niu 、 Niu Mei and Niu cola are both Nowcoder Loyal users of , It's the annual programmers' day (10 month 24 Number ), without doubt , They all log in Nowcoder 了 , Because they haven't finished the Niuke puzzle …
Nowcoder The administrator of wants to send them some simple login greeting messages , And expressed holiday wishes to them .
Please create a string that contains the string in turn ‘Niuniu’ 、‘Niumei’ and ‘Niu Ke Le’ A list of users_list,
Please use for Loop through the list user_list, List in turn users_list The name in the output line is similar to ‘Hi, Niuniu! Welcome to Nowcoder!’ String ,
for At the end of the cycle , Finally, a line of string is output “Happy Programmers’ Day to everyone!”
Input description : nothing
Output description : Output according to the title description .
Hi, Niuniu! Welcome to Nowcoder!
Hi, Niumei! Welcome to Nowcoder!
Hi, Niu Ke Le! Welcome to Nowcoder!
Happy Programmers’ Day to everyone!
Implementation code :
users_list = ['Niuniu', 'Niumei', 'Niu Ke Le']
for i in users_list:
print("Hi, %s! Welcome to Nowcoder! " % i)
print("Happy Programmers' Day to everyone!")
Running results :
Hi, Niuniu! Welcome to Nowcoder!
Hi, Niumei! Welcome to Nowcoder!
Hi, Niu Ke Le! Welcome to Nowcoder!
Happy Programmers' Day to everyone!
describe : Create a list my_list, It includes [1, 1 000] All integers in ,
Reuse min() and max() Verify that the list is from 1 Start , To 1 000 The end of the .
Besides , Then call the function on this list sum(), have a look Python What is the result of adding the thousand numbers .
Last , Average all integers in this list , Keep one decimal place directly .
Input description : nothing
Output description : Output three integers , A decimal fraction , Each number is on a single line .
Code implementation :
my_list = [i for i in range(1,1001)]
print(min(my_list))
print(max(my_list))
s = sum(my_list)
print(s)
print(round(s/1000,1))
Running results :
1
1000
500500
500.5
describe : By giving the function range() Specify the third parameter to create a list my_list, It includes [0, 19] All even numbers in ; Use one more for Loop to print out these numbers ( Each number is on a single line ).
Input description : nothing
Output description : Output according to the title description .
Implementation code :
my_list = list(range(0,20,2))
for i in my_list:
print(i)
Running results :
0
2
4
6
8
10
12
14
16
18
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 !!!