Write a program , Find all such numbers , They can be used 7 to be divisible by , But it can't be 5 Multiple ( stay 2000 and 3200 Between )( All included ). The obtained numbers should be printed on one line in comma separated order .
list=[]
for i in range(2000,3201):
if i%7==0 and i%5 !=0:
list.append(i)
else:
continue
print(list)
Output :
[2002, 2009, 2016, 2023, 2037, 2044, 2051, 2058, 2072, 2079, 2086, 2093, 2107, 2114, 2121, 2128, 2142, 2149, 2156, 2163, 2177, 2184, 2191, 2198, 2212, 2219, 2226, 2233, 2247, 2254, 2261, 2268, 2282, 2289, 2296, 2303, 2317, 2324, 2331, 2338, 2352, 2359, 2366, 2373, 2387, 2394, 2401, 2408, 2422, 2429, 2436, 2443, 2457, 2464, 2471, 2478, 2492, 2499, 2506, 2513, 2527, 2534, 2541, 2548, 2562, 2569, 2576, 2583, 2597, 2604, 2611, 2618, 2632, 2639, 2646, 2653, 2667, 2674, 2681, 2688, 2702, 2709, 2716, 2723, 2737, 2744, 2751, 2758, 2772, 2779, 2786, 2793, 2807, 2814, 2821, 2828, 2842, 2849, 2856, 2863, 2877, 2884, 2891, 2898, 2912, 2919, 2926, 2933, 2947, 2954, 2961, 2968, 2982, 2989, 2996, 3003, 3017, 3024, 3031, 3038, 3052, 3059, 3066, 3073, 3087, 3094, 3101, 3108, 3122, 3129, 3136, 3143, 3157, 3164, 3171, 3178, 3192, 3199]
Write a program , The factorial of a given number can be calculated , The results should be printed on one line in comma separated order , Suppose the following input is provided to the program :8
then , The output should be :40320
a=eval(input())
m=1
for i in range(a):
m=m*(i+1)
print(m)
Use the given integer n, Write a program to generate a (i,ixi) Dictionary , The dictionary is 1 To n Integer between ( All included ). The program should then print the dictionary . Suppose the following input is provided to the program :
8
then , The output should be
{1:1,2:4,3:9,4:16,5:25,6:36,7:49,8:64}
a=eval(input())
dic= {
}
for i in range(1,a+1):
dic[i]=i**2
print(dic)
Output :
{
1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
Write a program , The program accepts a comma separated sequence of numbers from the console , And generate a list and a containing each number
A tuple of words . Suppose the following input is provided to the program :
34,67,55,33,12,98
then , The output should be :
[‘34’, ‘67’, ‘55’, ‘33’, ‘12’, ‘98’]
(‘34’, ‘67’, ‘55’, ‘33’, ‘12’, ‘98’)
s=input()
l=s.split(",")
t=tuple(l)
#print(f" {l}")
#print(f" {t}")
print(l)
print(t)
Output :
['34', '67', '55', '33', '12', '98']
('34', '67', '55', '33', '12', '98')
Define a class that has at least two methods :
getString: Get string from console input
printString: Print the string in uppercase letters
Please also include simple test functions to test class methods
Write a program , Calculate and print the value according to the given formula :
Q = [(2 * C *D)/ H] The square root of
Here are C and H Fixed value of :
C by 50.H by 30.
D It's a variable. , Its values should be entered into your program in comma separated order , for example , Let's assume the following comma separated input sequence
The order is given to the program :
import math
c=50
h=30
list=[]
list=eval(input())
def gs(d):
q=math.sqrt((2*c*d)/h) return q m=[] for i in range(len(list)):
j=int((gs(list[i]))//1)
m.append(j)
m=','.join(str(i) for i in m)
print(m)
Output :
18,22,24
_ Write a program , The program will X,Y Two digits as input and generate a two-dimensional array . The first of an array of i Xing He j In column
The element value should be i * j.
Be careful :i = 0,1 …,X-1; j = 0,1,i(Y-1). Suppose the following input is provided to the program :3,5
then , The output of the program should be :
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
Write a program , The program accepts a comma separated sequence of words as input , And after sorting the words alphabetically, use
Print these words in comma separated order .
Suppose the following input is provided to the program :
without,hello,bag,world
then , The output should be :
bag,hello,without,world
Write a program that accepts a sequence of lines as input , And print lines after all the characters in the sentence are capitalized .
Suppose the following input is provided to the program :
Hello world
Practice makes perfect
then , The output should be :
HELLO WORLD
PRACTICE MAKES PERFECT
i=input()
s=i.upper()
print(s)
Write a program , The program accepts a series of words separated by spaces as input , And delete all duplicate words and press the first word
Print these words after sorting the parent numbers .
Suppose the following input is provided to the program :
hello world and practice makes perfect and hello world again
then , The output should be :
again and hello makes perfect practice world
Tips : We use set The number of duplicates automatically deleted by the container
According to the , And then use sorted() Sort the data .
Write a program , The program accepts comma separated 4 Bit binary digit sequence as input , Then check whether they can be 5
to be divisible by . By 5 Divisible numbers will be printed in comma separated order .
Example :
0100,0011,1010,1001
Then the output should be :
1010
Write a program , Find all between 1000 and 3000 Number between ( All included ), So that each digit of the number is
even numbers . The obtained numbers should be printed on one line in comma separated order .
list=[]
for i in range(1000,3001):
if i%2==0:
list.append(i)
else:
continue
list=','.join(str(i) for i in list)
print(list)
Write a program that accepts sentences and counts letters and numbers .
Suppose the following input is provided to the program :
hello world! 123
then , The output should be :
LETTERS 10
DIGITS 3
a=input()
b=0
xx=0
dx=0
c=0
for i in a:
if i.islower():
xx+=1
elif i.isupper():
dx+=1
elif i.isdigit():
c+=1
b=xx+dx
print("LETTERS %d"%b)
print("DIGIT %d"%c)
LETTERS 10
DIGIT 3
Write a program that accepts sentences , And calculate the number of upper and lower case letters .
Suppose the following input is provided to the program :
Hello world!
then , The output should be :
UPPER CASE 1
LOWER CASE 9
a=input()
b=0
xx=0
dx=0
c=0
for i in a:
if i.islower():
xx+=1
elif i.isupper():
dx+=1
elif i.isdigit():
c+=1
b=xx+dx
print("UPPER CASE %d"%dx)
print("LOWER CASE %d"%xx)
Write a program , Take the given number as a To calculate a + aa + aaa + aaaa Value .
Suppose the following input is provided to the program :
9
then , The output should be :
11106
a=eval(input())
b=a+a*11+a*111+a*1111
print(b)
Use list derivation to square each odd number in the list . The list is entered by a comma separated sequence of numbers .> Assume that the following inputs
Provide to the program :
1,2,3,4,5,6,7,8,9
then , The output should be :
1,9,25,49,81
list=[]
answer=[]
list=eval(input())
for i in list:
if i%2==1:
m=i**2
answer.append(m)
else:
continue
answer=','.join(str(i) for i in answer)
print(answer)
1,9,25,49,81
Write a program , The program calculates the net amount of the bank account based on the transaction log entered from the console . The transaction log format is as follows the
in :
D 100
W 200
D It means deposit ,W Means withdrawal .
Suppose the following input is provided to the program :
D 300
D 300
W 200
D 100
then , The output should be :
500
The website requires users to enter a user name and password to register . Write a program to check whether the password entered by the user is valid .
Here are the criteria for checking passwords :
[az] At least 1 Letters
[0-9] At least 1 A digital
[AZ] At least 1 Letters
[$#@] At least 1 Characters
Minimum length of transaction password :6
Maximum length of transaction password :12
Your program should accept comma separated password sequences , And will be checked according to the above conditions . The qualified password will be printed , Every time
Passwords are separated by commas .
Example
If you enter the following password as program input :
[email protected],a F1#,2w3E*,2We3345
then , The output of the program should be :
[email protected]
You need to write a program to sort... In ascending order ( name , Age , fraction ) Sort tuples , Where the name is a string , Age and branch
Numbers are numbers . Tuples are entered by the console . The sorting criteria are :
1: Sort by name
2: Then sort by age
3: Then sort by score
Priority is the name > Age > score .
If the following tuples are given as input to the program :
Tom,19,80
John,20,90
Jony,17,91
Jony,17,93
Json,21,85
then , The output of the program should be :
[(‘John’, ‘20’, ‘90’), (‘Jony’, ‘17’, ‘91’), (‘Jony’, ‘17’, ‘93’), (‘Json’, ‘21’,
‘85’), (‘Tom’, ‘19’, ‘80’)]
Define a class with a generator , The generator can iterate over a given range 0 and n Between can be 7 Divisible numbers .
Suppose the following input is provided to the program :
7
then , The output should be :
0
7
14
The robot starts from the original point (0,0) Start moving on the plane . The robot can follow a given step up , Next , Move left and right .
The trajectory of the robot is shown in the following figure :
UP 5
DOWN 3
LEFT 3
RIGHT 2
The number after the direction is the step size . Please write a program , To calculate the distance from the current position after a series of movements and original points . If
Distance is a floating point number , Then just print the nearest integer .
Example : If the following tuples are given as input to the program :
UP 5
DOWN 3
LEFT 3
RIGHT 2
then , The output of the program should be :
2
If the input data is provided to the question , It should be assumed that it is a console input . The distance here represents the Euclidean distance . Import math
Module to use sqrt function .
Write a program to calculate the frequency of words in the input . After sorting the keys alphabetically , Output should be output .
Suppose the following input is provided to the program :
New to Python or choosing between Python 2 and Python 3? Read Python 2 or Python 3.
then , The output should be :
2:2
3.:1
3?:1
New:1
Python:5
Read:1
and:1
between:1
choosing:1
or:2
to:1
Write a method that can calculate the square value of a number
a=eval(input())
b=a**2
print(b)
Python There are many built-in functions , If you don't know how to use it , You can read documents online or find some books . but yes
Python For each built-in function, there is a built-in document function .
Please write a program to print some Python Built in function documentation , for example abs(),int(),raw_input()
And add your own functional documentation
Define a class , This class has one class parameter and the same instance parameter .
Tips :
Define an instance parameter, need add it in init method.You can init an
object with construct parameter or set the value later
Define a function that can calculate the sum of two numbers .
Tips :
Define a function that takes two numbers as arguments . You can calculate the sum in the function and return the value .
def count(a,b):
c=a+b
return c
Define a function that can convert an integer to a string and print it in the console .
Tips :
Use str() Convert numbers to strings .
problem :
Define a function , This function can receive two integers in string form and calculate the sum of them , Then print it on the console
it .
Tips :
Use int() Convert string to integer .
Define a function , This function can take two strings as input and connect them , Then print it out in the console
Come on .
Tips :
Use + Number connection string .
Define a function , This function can accept two strings as input , And print the maximum length string in the console . If two
Two strings have the same length , Then the function should print all strings line by line .
Tips :
*** Use len() Function to get the length of the string .
a=""
b=""
a=input()
b=input()
a1=len(a)
b1=len(b)
if a1>b1:
print(a)
elif a1<b1:
print(b)
else:
print(a,b)
Define a function that can print dictionaries , The key is 1 To 20 Number between ( All included ), The value is the square of the bond .
def dict():
dic = {
i:i**2 for i in range(1,21)}
print(dic)
dict()
Define a function that can generate a dictionary , The key is 1 To 20 Number between ( All included ), The value is the square of the bond . The merit can
Only the keys should be printed .
def dict():
dic = {
i:i**2 for i in range(1,21)}
for j in range(1,21):
print(j)
dict()
Define a function , This function can generate and print a list , Where the value is between 1 To 20 The square of the number between ( Both include stay
Inside ).
def list():
list=[]
for j in range(1,21):
list.append(j**2)
print(list)
list()
Define a function , This function can generate a list , Where the value is between 1 To 20 The square of the number between ( Are included in
Inside ). then , This function needs to print the first... In the list 5 Elements .
def list():
list=[]
for j in range(1,21):
list.append(j**2)
print(list[0:5])
list()
Define a function , This function can generate a list , Where the value is between 1 To 20 The square of the number between ( Are included in
Inside ). then , This function needs to print the last... In the list 5 Elements .
def list():
list=[]
for j in range(1,21):
list.append(j**2)
print(list[15:20])
list()
Define a function , This function can generate a list , Where the value is between 1 To 20 The square of the number between ( All included )
def list():
list=[]
for j in range(1,21):
list.append(j**2)
print(list)
list()
For a given tuple (1,2,3,4,5,6,7,8,9,10), Write a program to print the first half of the value in one line , Then print the second half of the value in one line .
Tips :
Use [n1:n2] Representation gets a slice from a tuple .
tem =(1,2,3,4,5,6,7,8,9,10)
a=tem[0:5]
b=tem[5:10]
print(a)
print(b)
problem :
Write a program to generate and print another tuple (1,2,3,4,5,6,7,8,9,10) Tuples whose values are even in .
Tips :
Use “ for” To iterate over tuples . Use tuple() Generate a tuple from the list .
tuple1 = (1,2,3,4,5,6,7,8,9,10)
for i in range(len(tuple1)//2):
print(tuple1[i],end=' ')
print('\n')
for i in range(len(tuple1)//2,len(tuple1)):
print(tuple1[i],end=' ')
problem :
Write a program that accepts a string as input , If the string is “ yes” or “ YES” or “ Yes”, Then print “ Yes”, no
Then print “ No”.
Tips :
Use if Sentence judgment condition .
a=input()
if a=='Yes':
print("Yes")
else:
print("No")
problem :
Write a program , The program can map() Create a list , The elements of this list are [1,2,3,4,5,6,7,8,9,10] Yuan in Chinese
Square of prime .
Tips :
Use map() Generate list . Use lambda Defining anonymous functions .
def square(x):
return x**2
a=list(map(lambda x: x ** 2, [1, 2, 3, 4, 5,6,7,8,9,10])) # Use lambda Anonymous functions
print(a)
problem :
Write a program , The program can map() and filter() Make a list , The elements of this list are
[1,2,3,4,5,6,7,8,9,10] Even square of .
Tips :
Use map() Generate list . Use filter() Filter list elements . Use lambda Defining anonymous functions .
list_1 = [1,2,3,4,5,6,7,8,9,10]
def panduan(numble):
return numble**2
def panduan_1(numble):
return not numble&1
print(list(map(panduan,list(filter(panduan_1,list_1)))))
problem :
Write a program , The program can filter() Create a list , The elements of this list are 1 To 20 Even number between ( Both include stay
Inside ).
Tips :
Use filter() Filter the elements in the list , Use lambda Defining anonymous functions .
list_1 = [1,2,3,4,5,6,7,8,9,10]
def panduan(numble):
return numble**2
def panduan_1(numble):
return not numble&1
print(list(map(panduan,list(filter(panduan_1,list_1)))))
problem :
Write a program , The program can map() Create a list , The elements of this list are 1 To 20 Number squared between ( All inclusive enclosed
, ).
Tips :
Use map() Generate a list . Use lambda Defining anonymous functions .
def square(x):
return x**2
a=list(map(lambda x: x ** 2, [1, 2, 3, 4, 5,6,7,8,9,10])) # Use lambda Anonymous functions
print(a)
Define a name American Class , This class has a named printNationality Static method of .
class american():
def printnational(self):
print (" Lovely song song !")
a = american()
a.printnational()
class American(object):
@staticmethod
def printNationality():
print (" Cute pinch ")
anAmerican = American()
anAmerican.printNationality()
American.printNationality()
Define a name American Class and its subclasses NewYorker.
Tips :
Use class Subclass(ParentClass) Define a subclass .*
class american():
def printnational(self):
print (" Lovely song song ")
class newyorker(american):
def ga(self):
print (" Song song is cute ")
a = american()
b = newyorker()
a.printnational()
b.ga()
class American(object):
pass
class NewYorker(American):
pass
anAmerican = American()
aNewYorker = NewYorker()
print (anAmerican)
print (aNewYorker)
problem
Define a name Circle Class , This class can be constructed from radii .Circle Class has a method for calculating the area .
Tips
Use def methodName(self) Define a method .
Define a name Rectangle Class , This class can be constructed by length and width .Rectangle Class has a computable area
Methods .
Tips
Use def methodName(self) Define a method .
problem
Define a name Shape Class and its subclasses Square.Square Class has a init function , This function takes the length as an argument
Count . Both classes have a Area function , This function can print Shape The default area of is 0 The shape of the area .
Tips
To override methods in a superclass , We can define a method with the same name in the superclass .
problem
Please trigger RuntimeError abnormal .
Tips
U Use raise() Trigger exception .
problem
Write a function to calculate 5/0 And use try / except Capture exception .
Tips
Use try / except Capture exception .
problem
Define a custom exception class , This class takes string messages as properties .
Tips
To define a custom exception , We need to define a from Exception Inheritance of class
problem
Suppose we have some “ [email protected] ” Format email address , Please write a program to print to
User name for e-mail address . Both the user name and the company name consist of only letters .
Example : If you use the following e-mail address as input to this program :
[email protected]
[email protected]
join
Tips
Use \ w Match the letter .
Suppose we have some “ [email protected] ” Format email address , Please write a program to print to
The name of the company that set the e-mail address . Both the user name and the company name consist of only letters .
Example : If you use the following e-mail address as input to this program :
[email protected]
Output :
Write a program , The program accepts a sequence of words separated by spaces as input , To print only words consisting of numbers .
Example : If the following words are given as program input :
2 cats and 3 dogs
then , The output of the program should be :
[‘2’, ‘3’]
Tips
Use re.findall() Use regular expressions to find all substrings .
import re
list = input(" Please enter :")
pattern = "\d+"
ans = re.findall(pattern,list)
print(ans)
Print a unicode character string “ hello world”.
unicodeString = u"hello world!"
print(unicodeString)
Write a program to read ASCII String and convert it to utf-8 Coded unicode character string .
Tips
Use unicode()/ encode() Function transformation .
Write special notes to indicate Python The source code file is located in unicode in .
Tips
Use unicode() Function transformation .
Write a program , Enter the given... In the console n Input to calculate 1/2 + 2/3 + 3/4 + … + n / n + 1(n> 0).
Example : If the following n As input to the program :
5
then , The output of the program should be :
3.55
n=eval(input())
s=0
for i in range(1,n+1):
s+=i/(i+1)
print("%.2f"%s)
Write a program to calculate :
f(n)=f(n-1)+100 when n>0
and f(0)=0
Enter the given... Through the console n(n> 0).
Example : If the following n As input to the program :
5
then , The output of the program should be :
500
Tips
We can do it in Python Define recursive functions in .
def f(n):
if n==0:
return 0
else:
return f(n-1)+100
n=eval(input())
print(f(n))
Fibonacci series is calculated according to the following formula :
f(n)=0 if n=0
f(n)=1 if n=1
f(n)=f(n-1)+f(n-2) if n>1
Please write a program , Enter the given... In the console n Input to calculate f(n) Value .
Input :
7
The output should be :
13
def f(n):
if n==0:
return 0
elif n==1:
return 1
else:
return f(n-1)+ f(n-2)
n=eval(input())
print(f(n))
Fibonacci series is calculated according to the following formula :
f(n)=0 if n=0
f(n)=1 if n=1
f(n)=f(n-1)+f(n-2) if n>1
Please write a program , Enter the given... In the console n Input to calculate f(n) Value .
Example : If the following n As input to the program :
7
then , The output of the program should be :
0,1,1,2,3,5,8,13
Tips
We can do it in Python Define recursive functions in . Use list derivation to generate lists from existing lists . Use string.join() even
String list .
def f(n):
if n==0:
return 0
elif n==1:
return 1
else:
return f(n-1)+ f(n-2)
list=[]
n=eval(input())
for i in range(n+1):
list.append(f(i))
ans=",".join([str(i) for i in list])
print(ans)
When the console enters n when , Please use the generator to write a program , Print... In comma separated form 0 To n Even number between .
Example : If the following n As input to the program :
10
then , The output of the program should be :
0,2,4,6,8,10
def f(n):
for i in range(n+1):
if i%2==0 and i!=n:
print(i,',',end='')
elif i%2==0 and i==n:
print(i)
return ''
n=eval(input())
print(f(n))
Tips
Use yield To generate the next value in the generator .
When the console enters n when , Please use the generator to write a program , Printing in comma separated form can be done in 0 and n Between 5 and 7 whole
Number divided by .
Example : If the following n As input to the program :
100
then , The output of the program should be :
0,35,70
Tips
Use yield To generate the next value in the generator
def f(n):
for i in range(n+1):
if i%5==0 and i%7==0and i!=0:
print(',',i,end='')
elif i%5==0 and i%7==0 and i==0:
print(i,end='')
return ''
n=eval(input())
print(f(n))
Please write assert Statement to validate the list [2,4,6,8] Every number in is an even number .
Tips
Use “ Assertion expression ” To assert that .
Please write a program that accepts basic mathematical expressions from the console , And print the evaluation results .
Example : If the following n As input to the program :
35+3
then , The output of the program should be :
38
Tips
Use eval() Evaluation expression
expression = input(" Please enter the expression :")
answer = eval(expression)
print(answer)
Please write a binary search function , This function can search the items in the sorted list . This function should return the index of the element to be searched in the list .
Tips
Use if / elif Treatment conditions .
Please use Python The module generates a random floating point , Its value is 10 To 100 Between .
Tips
Use random.random() stay [0,1] Generate random floating point numbers in .
import random
rand_num = random.uniform(10,100)
print(rand_num)
problem
Please use Python The module generates a random floating point , Its value is 5 To 95 Between .
Tips
Use random.random() stay [0,1] Generate random floating point numbers in .
import random
rand_num = random.uniform(5,95)
print(rand_num)
problem
Please write a program using random modules and list derivation , To output between 0 To 10 Between ( contain 0 and 10) Random even number of .
Tips
Use random.choice() Handle random elements in the list .
import random
list = [i for i in range(0,11,2)]
print(random.choice(list))
problem
Please write a program to output a random number , Use random modules and lists to derive , The random number can be 5 and 7 to be divisible by , Be situated between 10
and 150 Between ( Include 10 and 150).
Tips
Use random.choice() Handle random elements in the list .
problem
Please write a program to generate a file containing 5 A random number ( Be situated between 100 and 200 Between , Include 100 and 200) A list of .
Tips
Use random.sample() Generate a list of random values .
import random
list = random.sample(range(100,201),5)
print(list)
problem
Please write a program to randomly generate a list , The list contains 100 to 200 Between ( Including both ends ) Of 5 An even number .
Tips
Use random.sample() Generate a list of random values .
import random
list = random.sample(range(100,201,2),5)
print(list)
Please write a program to randomly generate a containing 5 A list of numbers , These numbers can be 5 and 7 to be divisible by , And between 1 and 1000
Between ( contain 1 and 1000).
Tips
Use random.sample() Generate a list of random values
import random
list = [i for i in range(1,1001) if i%35 == 0]
ans = random.sample(list,5)
print(ans)
Please write a program to print randomly 7 To 15 An integer between .
Tips
Use random.randrange() To a random integer in a given range .
import random
print(random.randrange(7,16))
Please write a program to compress and decompress strings “ hello world!hello world!hello world!hello world!”.
Tips
Use zlib.compress() and zlib.decompress() Compress and decompress strings
Please write a program to print “ 1 + 1” Execution run time of 100 Time .
Tips
Use timeit() Function to measure run time .
Please write a program to play and print the list randomly [3,6,7,8].
Tips
Use shuffle() Function to play a random playlist .
Please write a program to generate all the sentences , Where the subject is located in [“ I”,“ You”] in , The verb lies in [“ Play”,“ Love”]
in , The object is located in [“ Hockey”,“ Football”] in .
Tips
Use list [index] Notation gets the element from the list
Please delete [5,6,77,45,22,12,24] Write a program to print the list after the even number in .
Tips
Use list derivation to remove a bunch of elements from the list
Understand by using lists , Please write a program to delete [12,24,35,70,88,120,155] Middle quilt 5 and 7 Divisible numbers , then
Print list .
Tips
Use list derivation to remove a bunch of elements from the list .
ls = [12,24,35,70,88,120,155]
ls2 = []
for i in ls:
if (i%7 !=0 and i%5 !=0):
ls2.append(i)
print (ls2)
Understand by using lists , Please write a program to delete [12,24,35,70,88,120,155] No 0、2、4、6 A digital ,
Then print the list .
Tips
Use list derivation to remove a bunch of elements from the list . Use enumerate() obtain ( Indexes , value ) Tuples .
list = [12,24,35,70,88,120,155]
list = [x for (i,x) in enumerate(list) if i%2!=0]
print(list)
Understand by using lists , Please write a program to delete [12,24,35,70,88,120,155] No 2 To 4 A digital , then
Print list .
Tips
*** Use list derivation to remove a bunch of elements from the list . Use enumerate() obtain ( Indexes , value ) Tuples .
list = [12,24,35,70,88,120,155]
list = [x for (i,x) in enumerate(list) if ( i== 1 or i2 or i3)]
print(list)
Understand by using lists , Please write a program , Generate a 3 * 5 * 8 3D Array , Each element is 0.
Tips
Use list derivation to create an array .
Understand by using lists , Please write a program to delete [12,24,35,70,88,120,155] No 0、4、5 A digital , then
Print list .
Tips
Use list derivation to remove a bunch of elements from the list , Use enumerate() obtain ( Indexes , value ) Tuples .
list = [12,24,35,70,88,120,155]
list = [x for (i,x) in enumerate(list) if i not in (0,4,5)]
print(list)
Understand by using lists , Please delete [12,24,35,24,88,120,155] The value in 24 Then write a program to print the list .
Tips
Use list's remove Method to delete a value
list = [12,24,35,24,88,120,155]
list = [x for x in list if x!=24]
print(list)
Use two given lists [1,3,6,78,35,55] and [12,24,35,24,88,120,155], Write a program to make a list , Its
The element is the intersection of the given list above .
Tips
Use set() and “&=” Perform intersection operation .
Use the given list [12,24,35,24,88,120,155,88,120,155], Write a program , After deleting all, keep the original order Of
After repeating values , Print this list .
Tips
Use set() Store many values , Can't repeat .
Define a class Person And its two subclasses :Male and Female. All classes have a method “ getGender”, It can be for
“ male ” Class printing “ male ”, by “ Woman ” Print “ Woman ”.
Tips
Use Subclass(Parentclass) Defining subclasses .
Please write a program , The program receives a string from the console , Then print it in reverse order .
Example : If the following string is used as program input :*
rise to vote sir
then , The output of the program should be :
ris etov ot esir
Tips
Use list [::-1] Iterate over the list in reverse order .
list=[]
list=input()
list=list[::-1]
print(list)
Please write a program , The program accepts a string from the console , And print characters with even index .
Example : If the following string is given as input to the program :
H1e2l3l4o5w6o7r8l9d
then , The output of the program should be :
Helloworld
Tips
Use list [:: 2] Pass step 2 Iteration list .
list=[]
list=input()
list=list[::2]
print(list)
Please write a print all [1,2,3] Arranged program
Tips
Use itertools.permutations() Get the arrangement of the list .
Write a program to solve the classical problems in ancient China : We counted the chickens and rabbits on the farm 35 The head and 94 leg . How many do we have
Rabbits and some chickens ?
Tips
Use for Iterating through all possible solutions .
According to your transcript on college sports day , You need to find the runner up . You will get points . Store them in the list and find
The score of the runner up .
If the following string is given as input to the program :
5
2 3 6 6 5
then , The output of the program should be :
5
Tips
Make the score unique , Then find the second place
Give you a string S Width and width W. Your task is to wrap the string into a length .
If the following string is given as input to the program :
ABCDEFGHIJKLIMNOQRSTUVWXYZ
4
then , The output of the program should be :
ABCD
EFGH
IJKL
IMNO
QRST
UVWX
YZ
Tips
Use textwrap Packaging function of the module
You will get an integer N. Your task is to print a N The letter of rangoli.(Rangoli It is a pattern based creation
Indian folk art form .)
Letter rangoli The different sizes of are as follows :
Tips
First print half of... In the given way Rangoli, And save each row in the list . Then print the list in reverse order to get
Take the rest of the information .
You have an appointment . Your task is to find the day of the week .
Input
One line input , Each of them contains MM DD YYYY Format separated months , Day and year .
08 05 2015
Output
Print the correct date in capital letters .
WEDNESDAY
Tips
Use the working day function of the calendar module
Given 2 Group integers M and N, Print their symmetry differences in ascending order . The term “ Symmetry difference ” It means to exist in M or N But not in both
Those values in .
Input
The first line of input contains an integer M, The second line contains M Space separated integers , The third line contains an integer N, In the fourth row
contain N Space separated integers .
4
2 4 5 9
4
2 4 11 12
Output
Output symmetric difference integers in ascending order , Each row of a .
5
9
11
12
Tips
Use ’^' Perform symmetric difference operation .
For you . Some words may be repeated . For each word , Output its occurrence times . The output order should be in the same order as the input of the word
Sequence corresponds to . See sample input / Output for clarification .
If the following string is given as input to the program :
4
bcdef
abcdefg
bcde
bcdef
then , The output of the program should be :
3
2 1 1
Tips :
List for input order , And create a dictionary to calculate word frequency
Give you a string , Your task is to calculate the frequency of the string letters and print the letters in descending order of frequency .
If the following string is given as input to the program :
aabbbccde
then , The output of the program should be :
b 3
a 2
c 2
d 1
e 1
Tips
Count frequencies with a dictionary and sort by values in dictionary items
Write a program that accepts strings and calculates numbers and letters Python Program .
Input :
Hello321Bye360
Output :
Digit - 6
Letter - 8
Tips
Use isdigit() and isalpha() function
Given number N. Use recursion from 1 To N Sum up
Input :
5
Output :
15
Tips
Perform a recursive operation to sum