题目86
import random
list1 = [ random. randint( 0 , 100 ) for _ in range ( 20 ) ]
list2 = list1[ : : 2 ]
list3 = list1[ 1 : : 2 ]
list_tmp = list1[ : ]
list2. sort( reverse= True )
print ( list1)
list1. clear( )
for i in range ( 10 ) : list1. extend( ( list2[ i] , list3[ i] ) )
print ( list1)
print ( list_tmp)
list_tmp[ : : 2 ] = sorted ( list_tmp[ : : 2 ] , reverse= True )
print ( list_tmp)
list1 = [ 1 , 2 , 3 , 4 , 5 , 6 ]
print ( list1)
list1[ : ] = [ 'a' for _ in range ( 6 ) ]
print ( list1)
list1[ : : 2 ] = [ 1 for _ in range ( 3 ) ]
print ( list1)
list1[ 1 : : 2 ] = [ 'cccc' for _ in range ( 3 ) ]
print ( list1)
list1[ 3 : 7 ] = [ 'DDDDD' for _ in range ( 3 ) ]
print ( list1)
list1[ 3 : 7 : 2 ] = [ 'FFFFFFF' for _ in range ( 2 ) ]
print ( list1)
题目87
def get_divisibility ( div: int ) : x = '9' while True : if not int ( x) % div: return len ( x) x += '9' while True : try : num = int ( input ( '请输入一个奇数:\n' ) ) if not num % 2 or not num % 5 : raise ValueError( ) cnt = get_divisibility( num) print ( f' { cnt} 个"9"能整除 { num} ' ) except ( ValueError, TypeError) : print ( '请输入一个位不是5个奇数!!!!!!!!!!!' )
题目88
a = 809
for i in range ( 10 , 100 ) : if 809 * i == 800 * i + 9 * i and 1000 <= 809 * i < 10000 and 10 <= 8 * i < 100 and 100 <= 9 * i < 1000 : print ( i) break
for i in range ( 10 , 100 ) : if i * 8 < 100 and i * 9 > 100 : print ( i) break
题目89
list1 = [ 1 , 2 , 3 , 4 , 5 ]
list2 = list1[ : ]
list3 = list1[ : ]
def right_move ( origin, step: int ) : tmp = origin[ : ] for i in range ( step) : tmp. insert( 0 , origin[ - i- 1 ] ) return tmp[ : len ( tmp) - step] print ( list1)
list1 = right_move( list1, 2 )
print ( list1)
print ( list2)
list2 = list2[ - 1 : - 1 - 2 : - 1 ] + list2[ : len ( list2) - 2 ]
print ( list2)
题目90
score = input ( '请输入成绩,成绩间用空格隔开:' )
print ( score)
score_list = [ int ( x) for x in score. split( ' ' ) if x not in [ ' ' , '' ] ]
high = max ( score_list)
low = min ( score_list)
print ( "输入成绩中的最高分与最低分的分差为:" , high - low)
score_list. sort( )
print ( "输入成绩中的最高分与最低分的分差为:" , score_list[ - 1 ] - score_list[ 0 ] )