当前位置:网站首页>Lesson 016: sequence | after class test questions and answers

Lesson 016: sequence | after class test questions and answers

2022-06-22 21:35:00 ChaseTimLee

Test questions :

0. We follow the list 、 The common characteristics of tuples and strings , Call them three together why ?

Sequence , Because they have the following in common :

1) You can get every element by index
2) The default index value is always from 0 Start ( Of course flexible Python Negative index is also supported )
3) You can get a set of elements in a range by sharding
4) There are many operators in common ( Repeat operator 、 Splicing operators 、 Membership operators )

1. What do you use respectively BIF, You can convert an iteratable object to a list 、 Tuples and strings ?

list([iterable]) Converting an iteratable object to a list

tuple([iterable]) Convert iteratable objects to tuples

str(obj) Convert an object to a string

>>> temp = 'I love FishC.com!'
>>> list(temp)
['I', ' ', 'l', 'o', 'v', 'e', ' ', 'F', 'i', 's', 'h', 'C', '.', 'c', 'o', 'm', '!']

2. You can also retell “ iteration ” The concept of ?

Iteration , It's an activity that repeats the feedback process , Its purpose is usually to approach and reach the desired goal or result . Every repetition of a process is called a “ iteration ”, The result of each iteration will be used as the initial value of the next iteration .

3. You think call max(‘I love FishC.com’) What value will be returned ? Why? ?

Returns the :‘v’, Because the string in the computer is in the form of ASCII In the form of code (ASCII Comparison table :http://bbs.fishc.com/thread-41199-1-1.html), Parameters in ASCII The largest code value is ’v’ Corresponding 118.

4. Ah ah , The little kids are so naughty now , Naughty children in the neighborhood , Draw a pattern of the code that the little turtle just wrote , Please restore the code of fish oil ~~

Alt


name = input(' Please enter the user name to be found :')
score = [[' Get lost ', 85], [' Night ', 80], [' Pudding ', 65], [' Froude doll ', 95], [' Yijing ', 90]]
IsFind = False

for each in score:
    if name in each:
        print(name + ' The score for is :', each[1])
        IsFind = True
        break
    
if IsFind == False:
    print(' The data found does not exist !')


use one's hands :

0. Guess min() This BIF Implementation process

def min(x):
   least = x[0]

   for each in x:
       if each < least:
           least = each

   return least

print(min('123456789'))

1. In the video we say sum() This BIF There's a flaw , If there is a string type in the parameter, an error will be reported , Please write a new implementation , Automatically “ ignore ” The string in the parameter and return the correct result

def sum(x):
    result = 0
    
    for each in x:
        if (type(each) == int) or (type(each) == float):
            result += each
        else:
            continue

    return result

print(sum([1, 2.1, 2.3, 'a', '1', True]))

原网站

版权声明
本文为[ChaseTimLee]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206222005194888.html