day4—day6作业(补发)
# 使用while循环输出1 2 3 4 5 6 8 9 10
# count = 0
# while count < 10:
# count += 1
# if count == 7:
# continue
# print(count)
'''
1、允许用户最多尝试3次
2、每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序
3、如果猜对了,就直接退出
'''
# age = "18"
# count = 1
# while True:
# guess = input("please input your age:")
# if guess == age:
# print("恭喜你")
# break
# else:
# print('猜错了')
# if count == 3:
# inp = input("》》:")
# if inp in ['Y','y']:
# count = 1
# continue
# elif inp in ['N','n']:
# break
# else:
# print("你tmd能不能好好输")
# break
# count += 1
# 求1-100的所有数的和
# n = 0
# count = 0
# while count < 100:
# n += count
# count +=1
# print(n)
# 输出 1-100 内的所有奇数
# count = 0
# while count < 100:
# count += 1
# if count % 2 == 1:
# print(count)
# 输出 1-100 内的所有偶数
# count = 0
# while count < 100:
# count += 1
# if count % 2 == 0:
# print(count)
# 求1-2+3-4+5 ... 99的所有数的和
n = 0
count = 1
while count <= 99:
if count % 2 == 0:
n -= count
else:
n += count
count += 1
print(n)
'''
*
***
*****
*******
*********
'''
h = 5
for a in range(1,h+1):
for i in range(h-a):
print(' ',end='')
for b in range(2*a-1):
print('*',end='')
print()
# 移除 s1 变量对应的值两边的
s1 = ' hello worl
# print(s1.strip(
# 判断 s1 变量对应的值是否以
# print(s1.starts
# 判断 s1 变量对应的值是否以
# print(s1.endswi
# 将 s1 变量对应的值中的 “
# print(s1.replac
# 将 s1 变量对应的值根据 “
# print(s1.split(
# 将 s1 变量对应的值变大写,
# print(s1.upper(
# 将 s1 变量对应的值变小写,
# print(s1.lower(
# 请输出 s1 变量对应的值的第
# print(s1[3])
# 请输出 s1 变量对应的值的前
# print(s1[ :4])
# 请输出 s1 变量对应的值的后
# print(s1[10: ])
# 请输出 s1 变量对应的值中
# print(s1.find('
# 获取子序列,去掉最后一个字符。
# s1 = ' hello wo
# s1[:5]
# print(s1[:5])
# 1、有列表`data = ['egon', 73, [1900, 3, 18]],
# 分别取出列表中的名字,年龄,出生的年,月,日赋值给不同的变量
# data = ['egon', 73, [1900, 3, 18]]
# name = data[0]
# age = data[1]
# l1 = data[2]
# year = l1[0]
# month = l1[1]
# sun = l1[2]
# 用列表模拟队列
# s1 = []
# s1.append(1)
# s1.append(2)
# s1.append(3)
# s1.append(4)
# s1.append(5)
# print(s1)
# s1.pop(0)
# print(s1)
# 用列表模拟堆栈
# l1 = []
# l1.append(1)
# l1.append(2)
# l1.append(3)
# l1.append(4)
# l1.append(5)
# print(l1)
# l1.pop()
# print(l1)
# 有如下值集合[11, 22, 33, 44, 55, 66, 77, 88, 99, 90...],
# 将所有大于 66 的值保存至字典的第一个key中,
# 将小于 66 的值保存至第二个key的值中
# 即:` {'k1': 大于66的所有值, 'k2': 小于66的所有值}`
# a1 = [11, 22, 33, 44, 55, 66, 77, 88, 99, 90]
# s1 = {}
# s2 = []
# s3 = []
# for i in a1:
# if i > 66:
# s2.append(i)
# elif i < 66:
# s3.append(i)
# s1['k1'] = s2
# s1['k2'] = s3
# print(s1)
# 统计`s='hello tank tank say hello sb sb'`中每个单词的个数
# 结果如:`{'hello': 2, 'alex': 2, 'say': 1, 'sb': 2}`
# s = 'hello tank tank say hello sb sb'
# s = s.split(' ')
# l1 = {}
# for i in s:
# l1[i] = s.count(i)
# print(l1)
# 有列表l = ['a', 'b', 1, 'a', 'a'],去重,
# 得到新列表,且新列表无需保持列表原来的顺序
# l1 = ['a', 'b', 1, 'a', 'a']
# l2 = set(l1)
# l3 = list(l2)
# print(l3)
"""
1. 求出即报名python又报名linux课程的学员名字集合
2. 求出所有报名的学生名字集合
3. 求出只报名python课程的学员名字
4. 求出没有同时这两门课程的学员名字集合
"""
p1 = {'egon', 'kevin', 'echo', 'owen', 'jason'}
l1 = {'egon', 'echo', 'tank', 'oscar'}
# print(p1 & l1)
# print(p1 | l1)
# print(p1 - l1)
# print(p1 ^ l1)