一.格式化输出
print("%s今年%s岁,爱好是%s,性别是:%s" % (name,age,hobby,gender))
%s 叫做占位符,(字符串)
%d叫做占位符,(整型,数字)
二.基本运算符
1.算数运算
+ 加 10+20=30
- 减 20-10= 10
* 乘 10*10=100
/ 除法 3/2=1.3
% 取余 3/%2=1
// 商取整 3//2=1
2.比较运算
= 等于
!= 不等于 <> 也是不等于
> 大于
<小于
>= 大于等于
<=小于等于
3.赋值运算
a=10
b=20
4.逻辑运算
not:真假反过来
and :同真为真,有假为假
or :有真为真,全假为假
运算顺序: not =>and => or
1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 ==> True
# 2)not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 ==>Flase
1),8 or 3 and 4 or 2 and 0 or 9 and 7 ==>8
# 2),0 or 2 and 3 and 4 or 6 and 0 or 3 ==>4
1)、6 or 2 > 1 ==>6
# 2)、3 or 2 > 1 ==>3
# 3)、0 or 5 < 4 ==>Flase
# 4)、5 < 4 or 3 ==>3
# 5)、2 > 1 or 6 ==>True
# 6)、3 and 2 > 1 ==>True
# 7)、0 and 3 > 1 ==>0
# 8)、2 > 1 and 3 ==>3
# 9)、3 > 1 and 0 ==>0
# 10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2 ==>2
每日作业:
# Day2作业及默写
# 1、判断下列逻辑语句的True,False.
# 1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 ==> True
# 2)not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 ==>Flase
# print (1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 ) # True
# print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 ) #Flase
# 2、求出下列逻辑语句的值。
# 1),8 or 3 and 4 or 2 and 0 or 9 and 7 ==>8
# 2),0 or 2 and 3 and 4 or 6 and 0 or 3 ==>4
# print(8 or 3 and 4 or 2 and 0 or 9 and 7) # 8
# print(0 or 2 and 3 and 4 or 6 and 0 or 3) # 4
# 3、下列结果是什么?
# 1)、6 or 2 > 1 ==>6
# 2)、3 or 2 > 1 ==>3
# 3)、0 or 5 < 4 ==>Flase
# 4)、5 < 4 or 3 ==>3
# 5)、2 > 1 or 6 ==>True
# 6)、3 and 2 > 1 ==>True
# 7)、0 and 3 > 1 ==>0
# 8)、2 > 1 and 3 ==>3
# 9)、3 > 1 and 0 ==>0
# 10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2 ==>2
# print(6 or 2 > 1)
# print(3 or 2 > 1)
# print(0 or 5 < 4)
# print(5 < 4 or 3)
# print(2 > 1 or 6)
# print(3 and 2 > 1)
# print(0 and 3 > 1)
# print(2 > 1 and 3)
# print(3 > 1 and 0)
# print(3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2)
# 4、简述变量命名规范
'''
1.字母,数字,下划线组合.
2.不可一使用数字开头,更不可使用纯数字.
3.要有意义
4.不可以太长
5.尽量不使用中文
6.禁止使用关键字
7.区分大小写
8.使用推荐的两种方式
①驼峰体:除了第一个单词外, if 其余单词首字母要大写
②下划线:每个单词之间要使用下划线分开
'''
#6.使用if语句完成猜字游戏,如果输入3次则显示你太笨了
# count = 1
# while count<=3:
# a = int(input("请输入一个数字:"))
# if a < 66:
# print("太小了")
# count = count + 1
# elif a > 66:
# print("太大了")
# count = count + 1
# elif a == 66:
# print('猜对了')
# break
#
# else:
# print("猜错3次,你好笨")
# 7.使⽤用while循环输⼊入 1 2 3 4 5 6 8 9 10
# count = 1
# while count <= 10:
# if count == 7:
# count = count + 1
# continue
# else:
# print(count)
# count = count + 1
# 8.求1-100的所有数的和
# count = 1
# sum = 0
# while count <= 100:
# sum = sum + count
# count = count + 1
# print(sum)
# 9.输出 1-100 内的所有奇数
# count = 1
# # while count <= 100:
# # if count % 2 != 0:
# # print(count)
# # count = count + 1
# # else:
# # count = count + 1
# 10.输出 1-100 内的所有偶数
# count = 1
# while count <= 100:
# if count % 2 == 0:
# print(count)
# count = count + 1
# else:
# count = count + 1
# 11.求1-2+3-4+5 ... 99的所有数的和.
# count = 1
# sum = 0
# while count <= 99:
# sum = sum + count*(-1)**(count - 1)
# count = count + 1
# print(sum)
# 12.⽤用户登陆(三次输错机会)且每次输错误时显示剩余错误次数
# (提示:使⽤用# 字符串串格式化)
# count = 1
# while count <=3:
# a = int(input("请输入密码:"))
# if a == 863:
# print("密码正确,登陆成功")
# break
# else:
# b = 3 - count
# print("密码输入错误,请重新输入,(还剩%s次机会)" % (b))
# count = count + 1
# else:
# print("今日已经输错3次密码,请明日再来")
# 13. ⽤用户输⼊入⼀一个数. 判断这个数是否是⼀一个质数(升级题).
# count = 2
# a = int(input("请输入一个数来判断是否是质数:"))
# if a == 1:
# print("不是质数")
# elif a ==2:
# print("是质数")
# else:
# while count < a:
# if a % count == 0:
# count = count + 1
# print("不是质数")
# break
# else:
# count = count + 1
# else:
# print("是质数")
# 输出200以内的质数
# b = 1
# while b <= 100:
# count = 2
# a = b
# if a == 1:
# print("")
# elif a == 2:
# print(b)
# else:
# while count < a:
# if a % count == 0:
# count = count + 1
# break
# else:
# count = count + 1
# else:
# print(b)
# b += 1
# 14. 输⼊入⼀一个⼴广告标语. 判断这个⼴广告是否合法.
# # 根据最新的⼴广告法来判断.⼴广 告法内容过多.
# # 我们就判断是否包含'最', '第⼀一', '稀缺', '国家级'等字样.
# # 如果包 含. 提示, ⼴广告不不合法
# a = input("请输入一句广告语:")
# if "最"in a or"第一" in a or"稀缺" in a or"国家级" in a:
# print("广告不合法")
# else:
# print("广告合法")
# 15. 输⼊⼀个数. 判断这个数是⼏位数(⽤算法实现)(升级题)
# 方法一
# a = input("请输入一个数字:").strip()
# b = len(a)
# print("输入的数字是%s位数" % (b))
# 方法二
# a = abs(int(input("请输入一个数字:"))) #abs() 取绝对值
# count = 1
# while True:
# if a < 10:
# print("你输入的是1位数")
# break
# elif a / 10 >= 10:
# a = a / 10
# count += 1
# else:
# print("你输入的是%d位数" % (count+1))
# break