第八周

def print_tic_tac_toe_grid(width):
# 检查输入是否为奇数
if width % 2 == 0:
print("请输入一个奇数作为田字格的宽度。")
return

# 打印上半部分的田字格
for i in range((width + 1) // 2):
    # 打印顶部的横线
    if i == 0:
        print('+' + '-' * (width - 2) + '+')
    else:
        # 打印中间的空格和竖线
        print(' ' * (width // 2) + '|' + ' ' * (width // 2 - 2) + '|' + ' ' * (width // 2))
    # 打印底部的横线(除了最后一行)
    if i != (width - 1) // 2:
        print('+' + '-' * (width - 2) + '+')

# 打印中间的十字部分(只有一行)
print(' ' * (width // 2) + '|' + ' ' * (width // 2))
print('+' + '-' * (width - 2) + '+')
print(' ' * (width // 2) + '|' + ' ' * (width // 2))

# 打印下半部分的田字格(与上半部分对称)
for i in range((width - 1) // 2, -1, -1):
    # 打印顶部的横线(除了第一行)
    if i != (width - 1) // 2:
        print('+' + '-' * (width - 2) + '+')
    # 打印中间的空格和竖线
    print(' ' * (width // 2) + '|' + ' ' * (width // 2 - 2) + '|' + ' ' * (width // 2))
    # 打印底部的横线(如果是最后一行则不打印)
    if i != 0:
        print('+' + '-' * (width - 2) + '+')

获取用户输入的田字格宽度

width = int(input("请输入田字格的宽度(奇数):"))
print_tic_tac_toe_grid(width)
n=eval(input())
def isOdd(n):
if n%20:
return False
else:
return True
print(isOdd(n))
n=eval(input())
def isPrime(n):
for i in range(2,n):
s=0
if n%i
0:
s=s+1
else:
s=s
if s>=1:
return False
else:
return True
print(isPrime(n))
n=eval(input())
def isPrime(n):
for i in range(2,n):
s=0
if n%i0:
s=s+1
else:
s=s
if s
0:
return n
else:
return ' '
for i in range(1,n+1):
print(isPrime(i))

posted @ 2025-04-20 14:09  彭66  阅读(16)  评论(0)    收藏  举报