# list is given [13, 'WWW', 'czie', '999', 'edu, 3.14]
Lt=[13, the 'WWW', 'czie', '999', 'edu, 3.14]
For the item in lt:
If lt index (item) % 2==0:
Lt [lt index (item)]='hello'
Print (lt)
# 2. Given a specific list, the inside of the element contains Numbers and characters, asked to write a piece of code, implementation:
#, eliminate all of the characters in the list elements;
#, will the new list (only contains Numbers) in order of elements since the childhood;
# output,
Str_num=[' hello ', 666999, 'world, 333]
For the item in str_num:
If isinstance (item, STR) :
Str_num. Remove (item)
Str_num. Sort ()
Print (str_num)
# 3. The realization of the four structure user login authentication code function of a random number,
The from string import who
Import the random
Code=[]
For _ in range (4) :
Code. Append (random choice (who))
Print ('. Join (code))
# 4. Lambda function is applied to 2-50 prime Numbers between (primes: can only be 1 or be divided exactly by yourself)
From the random import randint
Def is_prime (n) :
If n in (2, 3) :
Return False
If n % 2==0:
Return True
For I in range (3, int * * 0.5) (n + 1, 2) :
If I==0 n % :
Return True
Return False
LST=[randint (2, 50) for _ in range (48)]
Print (list (filter (lambda n: is_prime (n) is False, the LST)))
List=[]
I=2
For I in range (2, 50) :
J=2
For j in range (2, I) :
If (I % j==0) :
Break
The else:
List. Append (I)
Print (list)
# 4. Write the code requirements, according to input Celsius thermometer, automatic output "Fahrenheit" after the operation, calculation formula is: Fahrenheit=Celsius * 1.8 + 32
A=float (input (' please enter the Celsius temperature:))
C=a * 1.8 + 32
Print (" Celsius {} into Fahrenheit is: {} ". The format (a, c))
# 5. Write the code, requirements, according to the educational value of the input to calculate average score and total score,
Chinese_Score=int (input (' please enter the language subject result: '))
Math_Score=int (input (' please enter the mathematics subject achievement: '))
English_Score=int (input (' please enter the English subject result: '))
All_Score=Chinese_Score + Math_Score + English_Score
Average_Score=All_Score/3
Print (All_Score)
Print (Average_Score)
# 5. Write the code, to determine whether a user input year leap year and if so, the output "* * year is a leap year"; If not, the output "is not a leap year * * years" (note: * * user input year)
Year=int (input (" input a year: "))
If (year % 4)==0:
If (year 100) %==0:
If (year 400) %==0:
Print (" {0} is a leap year ". The format (year))
The else:
Print (" {0} is not a leap year ". The format (year))
The else:
Print (" {0} is a leap year ". The format (year))
The else:
Print (" {0} is not a leap year ". The format (year))
# 6. Any input two integers, output the least common multiple of two integers,
Def LCM (x, y) :
If x & gt; Y:
Greater=x
The else:
Greater=y
While (True) :
If (x=(greater %=0) and (greater % y==0)) :
LCM=greater
Break
Greater +=1
Return LCM
Num1=int (input (" input the first number: "))
Num2=int (input (" input the second number: "))
Print (num1, "and" num2, "the least common multiple of", LCM (num1, num2))
# 7. Using the random library and math library built-in functions: realize the randomly generated an integer, and output to the integer as the radius of the area of a circle,
Import the random
S='
For I in range (1) :
S +=STR (random randint (1, 9))
Print (s)
R=float (s)
The import math
Area=lambda r: math. PI * r * r
Print (area (r))
# note: the following questions if not through the custom function is complete, will deduct half the subject score
# 7. Write a function, the realization of 13 + 23 + + + 43 · · · · · · + n3 computing, in which, n is the number of user input;
Def mi () :
N=int (input (' please enter n: '))
Sum=0
For I in range (1, n + 1) :
The sum +=I * I * I
Print (sum)
(mi ())
# 8. Write a function, to achieve a given list "specific elements" in the statistics, the number of a given list is,33,24,33,25,32,12,33,87,66 [12],
# if statistics "12" is the output number is 2, if statistics "33", the output frequency is 3,
Def the count () :
Lt=[12, 33, 24, 33, 25, 32, 12, 33, 87, 66]
For the item in the set (lt) :
Print (item, lt count (item))
(the count ())
CodePudding user response: