今天學的是函數(emmmmmm)函數
import timeui
def H(a):3d
b=[ ' Joker ' ]blog
if a in b:input
time.sleep(1)it
print( ' OK ' )io
else:import
print( ' F ' )淘寶
--------------------------------這是一個例子-----------------------------密碼
簡單的淘寶購物車:
def C(g):
G=['汽車','火車','飛機']
if g in G:
Address()
else:
return False
def I(name,phone,Addr):
is_OK=True
if name == " " or name == " ":
is_OK=False
if len(phone) != 11:
is_OK=False
if Addr not in ['北京','山東']:
is_OK=False
return is_OK
def Address():
name=input('Name: ')
phone=input('Phone: ')
Addr=input('Address: ')
Note()
def Note():
print('發貨')
def Start():
print('光臨')
g=input('商品:')
C(g)
Start()
-----------------------------------------------------------------------------------------------------------------
註冊時用的密碼:
def Users():
users_ = input('Users:>>')
# Joker123
Z = 'ZXCVBNMASDFGHJKLQWERTYUIOPzxcvbnmasdfghjklqwertyuiop'
N = '1234567890'
T = '.*&^%$#@!~'
is_Z = False
is_N = False
is_T = True
for i in users_:
# 字母
if i in Z:
is_Z = True
# 數字
if i in N:
is_N = True
# 特殊字符
if i in T:
is_T = False
if is_Z and is_N and is_T:
pass
# Password()
else:
print('帳號必須含有數字和字母且不能含有(.*&^%$#@!~)')
Users()
---------------------------------------------------------------------------------------------------------------------------------------------------
倒計時:
import time
for seconds in range(10,0,-1):
time.sleep(1)
print('\33[5m %d秒以後 \r' %seconds,end=" ",flush=True) # \33[5m閃爍
這個Windows10貌似不支持,我看不出來效果。。。。
---------------------------------------------------------------------------------------------------------------------------------------------------
識別手機號是否合法(正則):
import re
compile_=re.compile('^1[3456789]\d{9}') #開頭是1,第二位是3456789,後面輸
a=input()
res=compile_.findall(a)
print(res)
---------------------------------------------------------------------------------------------------------------------------------------------------
# 下水道(可輸入不定長的參數)
def add(*Joker):
print(Joker)
a=add(input())
--------------------------------------------------------------------------------------------------------------------------------------------------
這是昨天課上的練習,下面記錄昨天的做業-------------
def add(*s):
print(s)
a=add
zs=0
fs=0
cs=0
sum_=0
while a !=0 :
a = eval(input("Enter an integer,the input ends if it is 0: "))
if a > 0:
zs += 1
if a < 0:
fs += 1
sum_ += a
if a != 0:
cs += 1
print('正數有',zs,'個')
print('負數有',fs,'個')
print('平均數爲: ',sum_ / cs)
答案:
Enter an integer,the input ends if it is 0: 1
Enter an integer,the input ends if it is 0: -9
Enter an integer,the input ends if it is 0: 6
Enter an integer,the input ends if it is 0: 0
正數有 2 個
負數有 1 個
平均數爲: -0.6666666666666666---------------------------------------------------------------------------------------------------好沒有了,下一篇見