上课的第三天。。。

今天学的是函数(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---------------------------------------------------------------------------------------------------好没有了,下一篇见
相关文章
相关标签/搜索