defLogin():
i =1while i <=3:
username =input("请输入账号:")
password =input("请输入密码:")if username =='wls'and password =='123456':print("欢迎登陆成功界面")breakelse:print("你的账号或密码错误")
i = i +1if __name__ =='__main__':
Login()
import math
defmoving(x,y,step,angle=0):
nx = x + step*math.cos(angle)
ny = y + step * math.sin(angle)return nx , ny
if __name__ =='__main__':
x,y = moving(20,20,50,111)print(x,y)
r = moving(20,20,50,111)print(type(r))
作业4:定义一个函数sam(a,b,c),接收3个参数,返回一元二次方程
a =2print(isinstance(a,int))print(isinstance(a,str))print(isinstance(a,(str,int,list,tuple)))import math
defsam(a,b,c):ifnot(isinstance(a,(int,float)))and(isinstance(b,(int,float)))and(isinstance(c,(int,float))):raise TypeError("a,b,c不全是数字")# if not isinstance(a,(int,float)):# raise TypeError("a不是一个数字")# if not isinstance(b,(int,float)):# raise TypeError("a不是一个数字")# if not isinstance(c,(int,float)):# raise TypeError("a不是一个数字")if a ==0:return'请输入不为0的值'else:
d = b*b -4*a*c
if d <0:return'无解'elif d ==0:
x =-b/(2*a)else:
x1 =(-b+math.sqrt(d))/(2*a)
x2 =(-b-math.sqrt(d))/(2*a)return x1,x2
if __name__ =='__main__':
a =float(input("a:"))
b =float(input("b:"))
c =float(input("c:"))print(sam(a,b,c))
文章目录作业1:写一个用户登陆(三次重试机会)(input输入账号和密码)作业2:把一个整数转化为八进制、二进制、十六进制表示的字符串作业3:利用math写一个返回多值的函数,并且能够打印出来作业4:定义一个函数sam(a,b,c),接收3个参数,返回一元二次方程作业1:写一个用户登陆(三次重试机会)(input输入账号和密码) def Login(): i = 1 while i <= 3: username = input("请输入账号:")