Lab 03
Lab 03
Lab 03
Xingkai [email protected]
Xizhi [email protected]
Catalog
• Solutions for Assignment 1
• Hints for Assignment 2
• Any other questions
Question 1
50 points
Grading points:
1. Capitalize words successfully (30 points)
2. Two words connected by ‘-’, i.e. Two-dimensional (10 points)
3. The first words in the sentence, i.e. ‘The Origin of’ (5 points)
4. Special professional terms ‘WTe2’ (5 points)
Code if ord(words[0])<123 and ord(words[0])>96: #only deal with a-z, skip A-Z
C_words = chr(ord(words[0])-32) + words[1:]
Capitalization function
else:
C_words = words
return C_words
Word = []
for i in range(len(text)):
if i==0:
flag = 0
else:
flag = 0
for j in prepositions:
if text[i]==j: main function
flag = 1
break
if flag:
word.append(text[i])
else:
word.append(Capitalized(text[i]))
Question 2
50 points
Grading points:
(a). Multiple inverses:12 totally (someone missed 1,1 and 25,25)
m=26
for a in range(0,26):
for b in range(1,26):
if (a*b)%m==1:
print(a,b)
print((7*15)%26)
print((7*3+18)%26)
(b). Almost correct
secret="computationalmethodsinphysics"
Question 3
N=9
last_row=[1]
for i in range(0,N+1):
last_row=[0]+last_row+[0]
this_row=[]
row=""
for j in range(i+1):
this_row.append(last_row[j]+last_row[j+1])
row=row+(4-len(str(this_row[j])))*" "+str(this_row[j])
front=" "*(2*(N+2)-int(len(row)/2)-2)
back=" "*(2*(N+2)-int(len(row)/2))
last_row=this_row
print(front+row+back)