Commit 4558b672 by BellCodeEditor

auto save

parent 5ec53ebb
Showing with 71 additions and 0 deletions
i = 3 #设置变量i,代表登录的次数
username = "python" #代表系统内存放的用户名
userpassword = "123456" #代表系统内存放的用户密码
while True: #重复执行
if i>0: #判断,如果i>0,也就是还有登录次数,就执行如果里面的代码
name = input("请输入用户名:") #实现用户输入用户名
password = input("请输入密码:") #实现用户输入用户密码
i -= 1 #每输入一次就把登录次数减少1
if name == username and password == userpassword: #如果输入的用户名密码和系统中的用户名密码一样,就显示登录成功
print("登录成功!")
break #跳出循环
if name != username: #如果输入的用户名和系统内已有的用户名不一样,就提示输入错误
print("用户名错误,请重新输入!")
print('温馨提示,您还有'+str(i)+"次机会")
continue #结束本次循环,进入下一次循环
if password != userpassword: #如果输入的密码和系统内已有的密码不一样,就提示输入错误
print("密码输入有误,请重新输入!")
print('温馨提示,您还有'+str(i)+"次机会")
else: #如果没有登录次数了,就显示以下的内容
print("你的账户已被锁定,请一个小时以后再来")
exit() #结束运行
print("欢迎来到贝尔编程!") #登录成功后,显示的内容
class Hero:
def __init__(self, name):
self.level = 1
self.hp = 250
self.attack = 40
self.name = name
def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack
if enemy.hp > 0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info = info1+info2+info3
print(info)
else:
info3 = enemy.name+"阵亡,游戏结束"
info = info1+info2+info3
print(info)
exit()
yase = Hero("垭瑟")
houyi= Hero("后羿")
yase.combat(houyi)
class TheStudent:
\ No newline at end of file
with open(r"C:\Users\admin\Desktop\bell.txt","w",encoding="utf-8") as file:
file.write("锦瑟[唐]\n 李商隐\n锦瑟⽆端五⼗弦,\n⼀弦⼀柱思华年。\n庄⽣晓梦迷蝴蝶,\n")
file.write("望帝春⼼托杜鹃。\n沧海⽉明珠有泪,\n蓝⽥⽇暖⽟⽣烟。\n此情可待成追忆,\n只是当时已惘然。\n")
new_i=""
with open(r"C:\Users\admin\Desktop\bell.txt","r",encoding="utf-8") as file:
for i in file:
if "蓝⽥⽇暖⽟⽣烟。" in i:
i=i.replace("蓝⽥⽇暖⽟⽣烟。","_____________")
new_i += i
with open(r"C:\Users\admin\Desktop\bell.txt","w",encoding="utf-8") as file:
file.write(new_i)
\ No newline at end of file
with open(r"c:\Users\admin\Documents\lesson13-1\sales_list.txt","r",encoding="utf-8") as file1:
a=file1.readlines()
for i in a:
data=i.split()
#print(data[1:])
sum=0
for b in data[1:]:
sum=sum+int(b)
c=data[0]+str(sum)
print(c)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment