①在电脑端输入出题数量n,依次生成 n道题目,每道题随机给出乘法或加法。
②每回答一道题时,若正确,则在 micro:bit端 LED阵列显示“笑脸”,否则显示“哭脸”。
③答完n道题目后,电脑端显示共练习了几道题,其中有几题回答正确。
电脑端程序:
import random
import serial
ser=serial.Serial()
ser.baudrate=115200
ser.port="COM4"
ser.open()
c=0;i=1
n=int(input("请输入题目数量:"))
while i<=n:
r=random.randint(0,1)
if r==0:
a=random.randint(1,9)
b=random.randint(1,9)
print(str(a)+"×"+str(b)+"=")
else:
a=random.randint(10,99)
b=random.randint(1099)
while ①____:
a=random.randint(10,99)
b=random.randint(10,99)
print(str(a)+"+"+str(b)+"=")
ans=int(input("请输入答案:"))
if r==0 and a*b==ans or r==1 and a+b==ans:
ser.write("H".encode())
c=c+1
else:
ser.write("S".encode())
i=i+1
print("共练习了"+str(n)+"题,其中有"+str(c)+"题回答正确。")
micro:bit端程序:
from microbit import *
while True:
if uart.any():
incoming=str(uart.read(),"UTF-8")
if :
display.show(Image.HAPPY)
else:
display.show(Image.SAD)
序号 | 访问地址 | 功能说明 |
1 | / | 主页,口算练习主要页面 |
2 | /login | 登录页,校对输入的用户名和密码是否正确。如正确则跳转到主页。 |
3 | /history | 历史记录页,显示用户自己答题的记录。 |
4 | /wrong | 错题页,显示用户自己错误的题目及高频错题。 |
根据网站页面规划,至少需要设计个视图函数。其中,访问错题页的URL是//。
程序代码如下:
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
img=np.array(Image.open("chenchen.jpg").convert("L"))
rows,cols=img.shape
for i in range(rows):
for j in range(cols):
if():
img[i,j]=1
else:
img[i,j]=0
plt.imshow(img,cmap="gray")
plt.show()
下列说法正确的是( )
s = "Li20An24K04ao" ; i = 0
while i < len( s ) :
if "A" <= s[ i ] <= "Z" :
s = s[ : i ] + s[ i + 1 : ]
elif "0" <= s[ i ] <= "9" :
s = s[ : i ] + str( ( int(s[ i ]) + 8 ) % 10 ) + s[ i + 1 : ]
else :
s = s[ : i ] + chr( ( ord( s[ i ] ) – 95 ) % 26 + 97 ) + s[ i + 1 : ]
i = i + 1
执行上述程序后,s的值为( )