1.设计一个猜数字的游戏(0~100)
基本功能: 不断输入数字,直到猜中为止提示游戏结束(大了,小了)
import random
random_num=random.randint(1,100)
while True:
num=int(input("please enter a num:"))
if num==random_num:
print("Congret!,you get the right answer!")
break
elif num<random_num:
print("%d is smaller than setting:"%num)
else:
print("%d is bigger than setting:" % num)
2.
filepath="//wbk.xlsx"
wbk = xlwt.Workbook()
sheet=wbk.add_sheet("Stu massage")
def inport_web():
print("******Welcome to student management system******")
# choice for login and register or back to welcome web
print("please choose:")
choices = ["1.login", "2.register", "3.withdrew"]
print("*****%s******"%choices[0])
print("*****%s******"%choices[1])
print("*****%s******"%choices[2])
selection=input()
if selection=="1":
func_login()
fuctions()
# 调用登录函数
elif selection=="2":
register()
# 调用注册函数
else:
pass
# 注册函数
def register():
print("******Welcome to student management system******")
print("register successfully!")
return name,password
#登录函数
def func_login():
print("******Welcome to student management system******")
name_set = "dawn"
password_set = "999999"
while True:
name1 = input("Please enter your name:")
if name1 == name_set:
password1 = input("Please enter you password:")
if password1==password_set:
print("Login in successfully!")
break
#查看学生信息
def fuctions():
print("******Welcome to student management system******")
choices=["1.添加学生信息","2.查看学生信息","3.修改学生信息","4.删除学生信息","5.返回"]
for str1 in choices:
print("@%s"%str1)
selection=int(input("请您输入要进行的功能:"))
if selection == 1:
add_stu()
if selection == 2:
find_stu()
if selection == 3:
rectiy_stu()
if selection == 4:
del_stu()
if selection == 5:
inport_web()
# 添加学生信息进入Excel:
def add_stu():
title = ['姓名', '年龄', '性别', '分数']
content=[]
for i in range(len(title)):
sheet.write(1,i+1,title[i])
times=2
while True:
name=input("请您输入学生姓名:")
sheet.write(times, 1, name)
age = int(input("请您输入学生年龄:"))
sheet.write(times, 2, age)
gender = input("请您输入学生性别:")
sheet.write(times, 3, gender)
score = input("请您输入学生分数:")
sheet.write(times, 4, gender)
# print("请判断是否要继续存入数据:(1/0)")
flag=int(input("请判断是否要继续存入数据:(1/0)"))
if flag==1:
times+=1
else:
wbk.save("Stu_massage")
inport_web()
break
def find_stu():
pass
def rectiy_stu():
pass
def del_stu():
pass
inport_web()