2019 Spring Python programming Exercise 3 (0402--0408)

1-1

As a is a list, and a [:] and a [:: - 1] are equal, the a elements in sequence to form a palindrome. (2 minutes)

         
1-3

Expression {1, 3, 2}> {1, 2, 3} is True. (2 minutes)

         
1-4

After x is non-empty list is known, then execute the statement x [0] = 3, the memory address list of object x unchanged. (2 minutes)

         
1-5

Python built elements are set in the order set by storing hash value of the element, not according to the order. (2 minutes)

         
1-6

Given that x is a list, then x = x [3:] + x [: 3] can be realized all the elements in the list of x cycles left by 3 bits. (2 minutes)

         
7-1 showing FIG dictionary (20 minutes)
 

Capture .JPG

Figure dictionaries representation. Multi-line input character string, the total length of each line and the length of one side is connected to the vertex and a vertex, the top output points, the number of edges, edges. FIG example, the 0:00 showing:
{ 'O': { 'A': 2, 'B':. 5, 'C':}}. 4. With the eval function to process the input, eval function of the specific use of built-in functions, see Chapter VI.

Input formats:

The first line indicates the number of rows per line following the input side and a string representing the length of a vertex connected to the vertex and

Output formats:

Output number of vertices in a row, the number of edges, the total length of the side

Sample input:

Here we are given a set of inputs. E.g:

4
{'a':{'b':10,'c':6}}
{'b':{'c':2,'d':7}}
{'c':{'d':10}}
{'d':{}} 

Sample output:

Given here corresponding output. E.g:

4 5 35
pointnum=int(input())
edgesum=0
edgenum=0
for i in range(pointnum):
  dictlist=eval(input())
  for j in dictlist:
    dict=dictlist[j]
    for k in dict:
      edgenum=edgenum+1
      edgesum=edgesum+dict[k]
    break
print(pointnum,edgenum,edgesum)
7-11 jmu-python- reverse order output (5 minutes)
 

String input line, then subjected to the following process.

Input formats:

String elements separated by a space or more spaces.

Output formats:

All elements in reverse output string.
Then output the original list.
Then reverse the output of each element of the original list, separated by an intermediate space. Note: The last element can not have spaces.

Sample input:

a b  c e   f  gh

Sample output:

ghfecba
['a', 'b', 'c', 'e', 'f', 'gh']
gh f e c b a

str=input()
list=[]
for s in str.split(): 
  list.append(s)
print("".join(list[::-1]))
print(list)            
print(" ".join(list[::-1]))    
7-12 jmu-python- class personnel information statistics (15 points)
 

Enter the list a, b class, and the following statistics.

Input formats:

Line 1 :: list of a class, a string of characters, each representing a student, no space, there may be repeated characters.
Line 2 list :: b class, a bunch of string, each separated by a student name or more spaces, there may repeat students.
Students participating in the third line :: acm contest, a bunch of string, each student name are separated by one or more spaces.
Line 4: students take an English competition, a bunch of string, each student name are separated by one or more spaces.
Line 5: Transfer of people (only 1 person).

Output Format

Special Note: when the output list of persons to be called sorted function, such as a collection of x, then print (sorted (x))
the number of outputs of the two classes of people all
outputs of the two classes did not participate in either ACM, did not participate in the English list and the number of
outputs of all persons to participate in the competition of the list and the number of
output both participated in the ACM, took part in the English competition of all persons and the number of
output took part in the ACM, a list of all persons not participating in the English contest
output take an English contest, did not participate in the ACM a list of all personnel
output list of participants only attended ACM or just take an English competition
last line: a student to transfer, you first need to determine whether the students in the class which then updates the class list, and output. If you do not at any class and do nothing.

Sample input:

abcdefghijab
1   2 3 4 5 6 7 8 9  10
1 2 3 a b c
1 5 10 a d e f
a

Sample output:

Total: 20
Not in race: ['4', '6', '7', '8', '9', 'g', 'h', 'i', 'j'], num: 9
All racers: ['1', '10', '2', '3', '5', 'a', 'b', 'c', 'd', 'e', 'f'], num: 11
ACM + English: ['1', 'a'], num: 2
Only ACM: ['2', '3', 'b', 'c']
Only English: ['10', '5', 'd', 'e', 'f']
ACM Or English: ['10', '2', '3', '5', 'b', 'c', 'd', 'e', 'f']
['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
a = input()
seta = set(a)    
b = input()
setb = set(b.split()) 
acm = input()
setacm = set(acm.split())
english = input()
setenglish = set(english.split())
zhuanxue = input()
Total = seta.union(setb) 
race = setacm.union(setenglish) 
Notinrace = Total.difference(race)
ACMplusEnglish = setacm.intersection(setenglish) 
OnlyACM = setacm.difference(setenglish)
OnlyEnglish = setenglish.difference(setacm) 
ACMOrEnglish = setacm.symmetric_difference(setenglish) 
print("Total:",len(seta.union(setb)))
print("Not in race:",sorted(Notinrace),end=", ")
print("num:",len(Notinrace))
print("All racers:",sorted(race),end=", ")
print("num:",len(race))
print("ACM + English:",sorted(ACMplusEnglish),end=", ")
print("num:",len(ACMplusEnglish))
print("Only ACM:",sorted(OnlyACM))
print("Only English:",sorted(OnlyEnglish))
print("ACM Or English:",sorted(ACMOrEnglish))
if zhuanxue in seta:
    seta.remove(zhuanxue)
    print(sorted(seta))
elif zhuanxue in setb:
    setb.remove(zhuanxue)
    print(sorted(setb))

 

 

Guess you like

Origin www.cnblogs.com/cts1234/p/11003933.html