Basic Data Types - Fun List for Getting Started with Python

Level 1: Addition, deletion, and modification of list elements: changes in the guest list

·Task Description
The task of this level: Add, delete, modify and other operations on a given list, and output the final list after the change.

·Programming Requirements
The programming task of this level is to complete the code of the src/Step1/guests.py file to realize the corresponding functions. The specific requirements are as follows:
step1: delete the element at the end of the guests list, and save the value of the deleted element to the deleted_guest variable
step2: insert deleted_guest into the index position of the guests list after step1 is deleted;
step3: process step2 Delete the element whose index position is 1 in the last guests list
and print out the deleted_guest variable of step1.
Print out the list of guests after step3 changes

I will test the code you wrote:
Test input:
zhang san
li si
wang wu
tan qi
hu ba
Expected output:
hu ba
['zhang san', 'hu ba', 'wang wu', 'tan qi']

# coding=utf-8
guests = []
while True:
    try:
        guest = input()
        guests.append(guest)
    except:
        break
deleted_guest = guests.pop() #step 1
guests.insert(2,deleted_guest) #step 2
guests.pop(1) #step 3
print(deleted_guest)
print(guests)

Level 2: Sorting List Elements: Sorting Guests

·Task Description
The task of this level: learn how to use operations related to list sorting, and realize the sorting of list elements.

·Programming requirements The
programming task of this level is to complete the function part in the src/step2/sortTest.py file, and it is required to sort the elements in the input list source_list according to the order of the first letter from small to large, and output the sorted list .

·Test instructions
I will test the code you write:

Test input:
zhang san
li si
wang wu
tan qi
hu ba
Expected output:
['hu ba', 'li si', 'tan qi', 'wang wu', 'zhang san']


#coding=utf-8
source_list = []
while True:
    try:
        list_element = input()
        source_list.append(list_element)
    except:
        break
source_list.sort()
print(source_list)

Level 3: List of values: speak with numbers

·Task Description
The task of this level: Use appropriate methods to quickly create a list of numbers, and be able to perform simple statistical operations on the values ​​of the elements in the list.

·Programming requirements
The programming task is to complete the code content of the src/Step3/numbers_square.py file to achieve the following functions:
step1: According to the given lower limit number lower, upper limit number upper and step size step, use the range function to generate a list
step2: Calculate the length of the list
step3: Find the difference between the largest element and the smallest element in the list

·Test description
I will test the code you wrote:
input 3 lines for each test, respectively representing the path of file_1, file_2, and file_3.

测试输入:
second_task/step4/test_a_1.txt
second_task/step4/test_b_1.txt
second_task/step4/output/out.txt

Expected output (students just need to finish writing results to file):
0
1
225
90
4
Expected output:
17
64

#coding=utf-8
lower = int(input())
upper = int(input())
step = int(input())
a_list=range(lower,upper,step) 
print(len(a_list)) 
print(a_list[-1]-a_list[0]) 


······Successful customs clearance······
If you have any questions, please correct me.

Guess you like

Origin blog.csdn.net/weixin_55764157/article/details/126402721