Home > other >  Create a Python programming function
Create a Python programming function

Time:09-19

Create a transition function from integer to an IP address, IP address format for WWW.XXX.YYY.ZZZ,
Teacher to lab assignments 1, the first question I card

CodePudding user response:

What form will turn what form? For example

CodePudding user response:

Oh yes:
Num=132
0.0.0.132

Num=4582136977889511
230.225.24.231

CodePudding user response:

reference 1st floor chuifengde response:
what form what form? For example

Num=132
0.0.0.132

Num=4582136977889511
230.225.24.231
Look down the four line leak

CodePudding user response:

256 conversion?
 
S=4582136977889511
Def change (s) :
Result=[]
For I in range (1, 5) :
S1=s % 256
S=int (s/256)
Result. The append (s1)
Result. The reverse ()
Return ". ". The join (STR (result) [I] for I in range (0, 4))

Print (change (s))
Print (change (132))

CodePudding user response:

reference 4 floor weixin_45903952 response:
256 conversion?
 
S=4582136977889511
Def change (s) :
Result=[]
For I in range (1, 5) :
S1=s % 256
S=int (s/256)
Result. The append (s1)
Result. The reverse ()
Return ". ". The join (STR (result) [I] for I in range (0, 4))

Print (change (s))
Print (change (132))

256 of conversion is what
On these, the teacher gave the topics has been let's create a function, this function can be run as a result, I try you wrote

CodePudding user response:

reference 5 floor Python_baby_ reply:
Quote: refer to 4th floor weixin_45903952 response:
256 conversion?
 
S=4582136977889511
Def change (s) :
Result=[]
For I in range (1, 5) :
S1=s % 256
S=int (s/256)
Result. The append (s1)
Result. The reverse ()
Return ". ". The join (STR (result) [I] for I in range (0, 4))

Print (change (s))
Print (change (132))

256 of conversion is what
On these, the teacher gave the topics has been let's create a function, this function can be run as a result, I try you wrote



230.225.24.231
0.0.0.132

CodePudding user response:

refer to 6th floor weixin_45903952 response:
Quote: refer to the fifth floor Python_baby_ reply:

Quote: refer to 4th floor weixin_45903952 response:
256 conversion?
 
S=4582136977889511
Def change (s) :
Result=[]
For I in range (1, 5) :
S1=s % 256
S=int (s/256)
Result. The append (s1)
Result. The reverse ()
Return ". ". The join (STR (result) [I] for I in range (0, 4))

Print (change (s))
Print (change (132))

256 of conversion is what
On these, the teacher gave the topics has been let's create a function, this function can be run as a result, I try you wrote



230.225.24.231
0.0.0.132

I changed a little, the num=int (input (" num=")) so that the results conform to the topic, I can not ask the teacher this code

CodePudding user response:

You can, then use change (num)

CodePudding user response:

refer to the eighth floor weixin_45903952 response:
, then use change (num) ok

Yes, I have to consider this code, the teacher said the can, thank you!
  • Related