3月20号
定义变量:
sex = input('请输入你的性别:')
if sex =='男'or sex=='女':
print('性别合法')
else:
print('性别输入错误!')
if sex!='男' and sex!='女':
print ('性别 未知')
print('程序运行结束')
age = input('请输入你的年龄')
age =int(age) #类型转换,转成int类型
if age<18:
print('未成年人')
else:
print('成年人')
score=input('请输入你的成绩')
score = int(score)
if score>90:
print('优秀')
elif score>=75 and score<90:
print('良好')
elif score>=60 and score<75:
print('及格')
else:
print('不及格')
3月21
条件判断
import random
num = random.randint(1,10)#随机产生一个1=10之间的数字
print('随机产生数字是:',num)
new_num = input('请输入你要猜的数字是多少:')
new_num=int(new_num)
if new_num>num:
print('输入大了')
elif new_num<num:
print('你输入数字太小了')
else:
print('共享你猜对了')
3月22号
for循环
for i in range(3):
print('hell world!')
#必须加冒号:if else、while、for,下一行字段缩进
#字符串格式化
import datetime
today = datetime.date.today()
username =input('请输入用户名:')
welcome='欢迎光临:'+username #第一种方式
welcome ='欢迎光临:%s 今天的日期是:%s'%(username,today)#占位符
#¥字符串 %d 整数
print (welcome)
age=18
score=98.6
info='你的用户名是%s 年龄是 %d 成绩是%.2f'%(username,age,score)
print (info)
3月23
while循环
count =0
while count<3:
if count==2:
print('22222')
break
count+=1
else:
print('循环结束!')
#while循环对应一个else的时候,循环正常结束后