Python指令碼 基礎指令碼訓練

2021-07-11 04:54:40 字數 3407 閱讀 7980

目錄

python 基礎指令碼

1、random:隨機數模組,首先import random模組

1、random.random() 生成[0.0,1.0)的隨機浮點數

2、random.randint(x,y)生成(x,y)指定區間的隨機整數

3、random.unfiorm(x,y)生成(x,y)之間的隨機浮點數

4、random.randrange(start,stop,[step])生成乙個指定步進的隨機整數

5、random.choice(sequence)隨機抽取序列型別中的乙個元素

6、random.sample(sequence,n)生成隨機從sequence中抽取n個元素組合的新的list物件

7、random.shuffle(list)打亂乙個list物件中元素的順序

2、「stars」指令碼

3、隨機數比較大小

4、修改密碼

5、1-100能被5整除的數顯示出來

6、查詢是否存在namelist中

>>> int(random.random()*100+1)
>>>random.randint(1,100)
>>>random.uniform(10,20)
>>>random.randrange(10,100,10)
>>>number= [1,3,4,5,6,8,0,15,56,763]

>>>random.choice(number)

>>>namelist=["jimmy","xiao","miao","bao","hello","world"]

>>>random.sample(namelist,2)

>>>random.shuffle(number)
vim /opt/workspace/pyhon/stars.py

#!/usr/bin/env python

#conding=utf8

n = 20

m = 0

for x in range(0,20):

print ' '*m + (2*n-1)*'*'

m += 1

n -= 1

vim /opt/workspace/pyhon/numberand.py

#!/src/bin/env python

#coding=utf8

number1 = 10

number2 = int(raw_input("pls neter a number: "))

print "number1 value:%d"  %  (number1)

if number2 > number1:

print "number2 > number1"

print "done test"

elif number2 < number1:

print "number2 < number1"

print "done test"

else:

print "number2 = number1"

print "done all test."

vim /etc/opt/python/passwd.py

#!/usr/bin/env python

def doublecheckinput(input1,input2="jimmy"):

if input1 == input2:

print "the password is right!"

print "value of input2:%s" % input2

return 1

else:

print "pls check the passwork and enter again."

return 0

def changethepwd(input1,input2):

if input1 == input2:

print "the pwd setup successfully"

return 1

else:

print "error:pls check the enter and enter again!"

return 0

if __name__ == '__main__':

oldpwd1 = raw_input("pls enter the pwd:")

reslove = doublecheckinput(oldpwd1)

if reslove == 1:

newpwd1 = raw_input("pls enter the new pwd:")

newpwd2 = raw_input("pls enter the new pwd again:")

changepwdreslove = changethepwd(newpwd1,newpwd2)

if changepwdreslove == 1:

print "change done"

else:print "error:change failed"

else:

print "the pwd is worng"

print "done"

vim /etc/opt/python/five.py

#!/usr/bin/env python

#coding=utf8

import sys

i = 101

count = 0

while(i>0):

i -= 1

if i%5:

continue

print i,

count += 1

print "done"

print "execution times:%d" % count

vim /etc/opt/python/namelist.py

#!/src/bin/env python

namelist = ['jimmy','mikey','wen','pan']

classmatename = raw_input("pls enter the classmatename: ")

if classmatename in namelist:

print "the %s in the class" % classmatename

else:

print "not in"

print "done all"

python指令碼環境 在python指令碼中更改環境

我有乙個關於python和linux環境變數的問題。我在這裡讀了很多問題 答案,但沒有乙個是我的。接下來是 在install and create virtualenv easy install prefix opt mypython pip bashrc module unload python ...

Linux Shell指令碼基礎

shell指令碼在處理自動迴圈或大的任務方面可節省大量時間,且功能強大。任何指令碼都可能有注釋,加注釋需要此行的第乙個字元為 直譯器對此行不予解釋。指令碼不是複雜的程式,它是按行解釋的。指令碼第一行總是以 bin sh開始,這段指令碼通知shell使用系統上的 bourne shell直譯器。指令碼...

bash指令碼基礎

shell 指令碼 一 如何建立新shell指令碼?1.建立包含bash命令的文字檔案。檔案第一行應為 bin bash 2.使檔案可執行 使用chmod x scripts 3.將檔案放置在使用者的 path的目錄中 bin 用於使用者的私有程式 usr local bin 本地開發 系統上的其他...