#第一题

defdec2bin_Int(dec):

binum=”

#请在此添加代码,补全函数dec2bin_Int

#———–Begin———-

whiledec!=0:

r=dec%2

ifr==1:

binum=binum+”1″

ifr==0:

binum=binum+”0″

dec=dec//2

#————End———–

returnbinum[::-1]

#第二题

defdec2bin_Point(dec,length):

binum=”

#请在此添加代码,补全函数dec2bin_Point

#———–Begin———-

len_=1

whiledec!=0andlen_<=length:

dec=dec*2

ifdec>1:

binum=binum+”1″

dec=dec-1

else:

binum=binum+”0″

len_+=1

#————End———–

return’0.’+binum

#第三题

defbin2oh(binum,oh):

result=”

ifoh==’o’:

#请在此添加代码,补全函数bin2oh

#———–Begin———-

length=len(binum)

whilelength%3!=0:

binum=’0’+binum

length=len(binum)

foriinrange(0,length,3):

i_result=int(binum[i])*4+int(binum[i+1])*2+int(binum[i+2])

result=result+str(i_result)

#————End———–

returnresult

elifoh==’h’:

#请在此添加代码,补全函数bin2oh

#———–Begin———-

length=len(binum)

whilelength%4!=0:

binum=’0’+binum

length=len(binum)

foriinrange(0,length,4):

i_result=int(binum[i])*8+int(binum[i+1])*4+int(binum[i+2])*2+int(binum[i+3])

dic={10:”A”,11:”B”,12:”C”,13:”D”,14:”E”,15:”F”}

ifi_result>=10:

i_result=dic[i_result]

result=result+str(i_result)

#————End———–

returnresult

fromrandomimport*

defmakechange(num):

changes={}

numint=int(num)

numdec=round(num-numint,2)

#请在此添加代码,补全函数makechange

#———–Begin———-

foriin[50,20,10,5,2,1]:

ifnumint>=i:

changes[i]=numint//i

numint=numint%i

numdec=numdec*100

foriin[0.5,0.2,0.1,0.05,0.02,0.01]:

ifnumdec>=i*100:

changes[i]=int(numdec//(i*100))

numdec=numdec%(i*100)

#————End———–

returnchanges

if__name__==’__main__’:

seed(0)

foriinrange(10):

num=round(random()*100,2)

print(sorted(makechange(num).items(),key=lambdaitem:item[0],reverse=True))

importmath

defencryptMessage(key,message):

#请在此添加代码,补全函数encryptMessage

#———–Begin———-

length=len(message)

whilelength%key!=0:

length+=1

message_key=””

foriinrange(key):

forjinrange(i,len(message),key):

message_key+=message[j]

returnmessage_key

#————End———–

defdecryptMessage(key,message):

#请在此添加代码,补全函数decryptMessage

#———–Begin———-

message_de=”

n=len(message)/key

ifn>len(message)//key:

n+=1

n=int(n)

m=n*key-len(message)

single=key-m

totle=0

foriinrange(n):

count=0

j=i

whilecount<keyandtotle<len(message):

ifcount>single:

j-=1

message_de+=message[j]

totle+=1

j+=n

count+=1

returnmessage_de

#————End———–

if__name__==’__main__’:

messages=[“Behindeverysuccessfulmanthere’salotofunsuccessfulyears.”,

‘Commonsenseisnotsocommon.’,

‘Therearenosecretstosuccess.Itistheresultofpreparation,hardwork,andlearningfromfailure.’,

‘Allthingsaredifficultbeforetheyareeasy.’]

formessageinmessages:

forkeyinrange(8,10):

encrytext=encryptMessage(key,message)

print(encrytext)

print(decryptMessage(key,encrytext))