控制流作业
控制流作业
# ————————-*题—————————#
number = input(‘请输入一个整数:’)
if (int(number)%7 == 0) | (number.find(‘7’) != -1):
print(‘该数与7相关’)
else:
print(‘该数与7无关’)
# ————————-第二题—————————#
id = input(‘请输入身份证号码:’)
if len(id) == 18:
birthday = id[6:14]
print(‘你的出生日期是:’,birthday)
elif len(id) == 15:
birthday = ’19’ + id[6:12]
print(‘你的出生日期是:’,birthday)
else:
print(‘请重新输入身份证号码!’)
# ————————-第三题—————————#
id = input(‘请输入身份证号码:’)
if len(id) == 18:
if int(id[-2]) % 2 == 0:
print(‘女’)
else:
print(‘男’)
elif (len(id)) == 15:
if int(id[-1]) % 2 == 0:
print(‘女’)
else:
print(‘男’)
else:
print(‘请重新输入身份证号码!’)
# ————————-第四题—————————#
list6 = [1,5,2,8,10,13,17,4,6]
## 方法一:
result = []
for i in list6:
result.append(i**2+1)
print(result)
## 方法二:
result = [i**2+1 for i in list6]
print(result)
# ————————-第五题—————————#
list7 = [‘one’,’two’,’three’,’four’,’five’,’six’,’seven’,’eight’,’nine’]
## 方法一:
result = []
for i in list7:
if i.find(‘e’) != -1:
new_i = i.replace(i[:],’^-^’)
result.append(new_i)
else:
result.append(i)
print(result)
## 方法二:
result = [i for i in list7 if i.find(‘e’)!=-1]
print(result)
#————————-第六题—————————#
# 同第四题
# ————————-第七题—————————#
list8 = [‘A’,’C’,’A’,’C’,’B’,’C’,’A’,’A’,’B’,’C’]
dict = {}
for i in set(list8):
dict[i] = list8.count(i)
print(dict)
# ————————-第八题—————————–#
n = 1
s = 0
while s<=1000:
s += 3*n+5
n += 1
print(n,’–>’,s)
# ————————–第九题—————————–#
import random
A = int(input(‘范围*小值:’))
B = int(input(‘范围*大值:’))
number = random.randint(A,B)
while True:
guess = int(input(‘请在{}、{}之间猜一个整数:’.format(A,B)))
if guess > number:
B = guess
elif guess < number:
A = guess
else:
print(‘你真棒,猜中了。’)
break