# python头歌-python第五章作业

``````def isprime(n):
for j in range(2, int(n**(1/2)) + 1):
if n % j == 0:
return 0
return 1

def plalindrome_prime(n):
n1 = n[::-1]
if n1 == n:
return 1
return 0

x = int(input())
i = 0
n = 2
while (i < x):
if (isprime(n) and plalindrome_prime(str(n))):
print(n, end=' ')
i += 1
n += 1``````

``````def is_prime(n):
for i in range(2,int(n**(1/2)+1)+1):
if n % i ==0:
return False
return True
def reverse_prime(n):
if is_prime(n) and is_prime(int(str(n)[::-1])) and str(n) !=str(n)[::-1]:
return True
else:
return False
a = int(input())
times = 0
n = 2
while times < a:
if reverse_prime(n):
print(n,end = " ")
times += 1
n +=1``````

``````def is_prime(n):
"""判断素数的函数,接收一个正整数为参数，参数是素数时返回True，否则返回False"""
# ====================Begin===================================
# 补充你的代码
if n < 2:
return False
elif n == 2:
return True
else:
a = int(n ** (1 / 2) + 1)
for i in range(2, a + 1):
if n % i == 0:
return False
else:
return True
# ======================End=================================

def goldbach_conjecture(num):
""" 哥德巴赫猜想, 接收一个不小于4的正整数为参数。
当参数为不小于4的偶数时，将其分解为两个素数的加和，按小数+数的格式输出。
有多种组合时全部输出，但不输出重复的组合，例如输出8=3+5，不输出8=5+3。
参数为奇数或小于4时，输出'Data error!'
"""
# ====================Begin===================================
# 补充你的代码

if 4<=num and num % 2 == 0:
for i in range(1,num + 1):
n = num - i
if is_prime(i) and is_prime(n) and i<=n :
print(f"{num}={i}+{n}")
else:
print('Data error!')

# ======================End=================================

if __name__ == '__main__':
positive_even = int(input())  # 输入一个正数
goldbach_conjecture(positive_even)``````

``````a = input()
b = eval(input())
if '\$' in a and b>0:
c = eval(a.replace('\$',""))
print(f"{c*b:.2f}¥")
elif "¥" in a and b>0:
c = eval(a.replace('¥', ""))
print(f"{c/b:.2f}\$")
else:
print("Data error!")``````

``````a = list(map(str,input().split()))
b = []
c=0
for i in a[4]:
if str.isdigit(i) and c <4:
b.append(i)
c+=1
b = ''.join(b)
print("姓名：" + a[1])
print("班级：" + a[2])
print("出生：" + str(b)+"年")``````

``````a = input()
year = a[6:10]
month = a[10:12]
date = a[12:14]
if int(a[16])%2 == 0:
print(f'出生：{year}年{month}月{date}日')
print('性别：女')
else:
print(f'出生：{year}年{month}月{date}日')
print('性别：男')``````

``````[print(i,end = ' ') for i in range(1,int(input()) + 1) if sum(map(int,str(i)))==5]
# n = int(input( ))
# for i in range(1,n+1);
#     if sum(map(int,str(i)))==5;
#         print(i,end = ' ')``````

``print(len(input()))``

``````table = {'a': 'd', 'b': 'e', 'c': 'f', 'd': 'g', 'e': 'h', 'f':
'i', 'g': 'j','h': 'k', 'i': 'l', 'j': 'm', 'k': 'n', 'l': 'o',
'm': 'p', 'n': 'q', 'o': 'r', 'p': 's', 'q': 't', 'r': 'u', 's':
'v', 't': 'w', 'u': 'x', 'v': 'y', 'w': 'z', 'x': 'a', 'y': 'b',
'z': 'c', 'A': 'F', 'B': 'G', 'C': 'H', 'D': 'I', 'E': 'J', 'F':
'K', 'G': 'L', 'H': 'M', 'I': 'N', 'J': 'O', 'K': 'P', 'L': 'Q',
'M': 'R', 'N': 'S', 'O': 'T', 'P': 'U', 'Q': 'V', 'R': 'W', 'S':
'X', 'T': 'Y', 'U': 'Z', 'V': 'A', 'W': 'B', 'X': 'C', 'Y': 'D',
'Z': 'E'}
text = input()
for c in text:
print(table. get(c,c), end='')``````

``````s=input().split()
for i in s:
print(i)``````

``````s=input()
for c in s:
if c.islower():
print(c.upper(),end='')
elif c.isupper():
print(c.lower(),end='')
else:
print(c,end='')``````

``````c=input()
str=input()
pos= str.find(c)
if pos== -1:
else:
print('index = {}'.format(pos))``````

``````import random
characters ='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#\$%&()*+,-.'
n,s=map(int,input().split(','))
random.seed(s)
key=''
for i in range(n):
key+=random.choice(characters)
print(key)``````

``````import random
def key(num):
for _ in range(num):
keySn=[]
for i in range(5):
s=''
characters='BCEFGHJKMPQRTVWXY2346789'
for i in range(5):
s = s + random.choice(characters)
keySn.append(s)
key='-'.join(keySn)
print(key)
if __name__ == '__main__':
num = int(input())
n=int(input())
random.seed(n)
key(num)``````

``````A=input()
num = int(input())
if 1<= int(A) <=9 and num >= 0:
print(sum([int(A * i) for i in range(1,num +1)]))
else:
print('data error')``````

``print(len(input().split()))``

THE END