实现该功能的VB程序段如下:
Function space(x As Integer)As String ‘输出格式化,设置左侧的空格数量
Dim n As Integer
For n=9 To x Step-1
①
Next n
End Function
Private Sub Form_Load()
Dim t As Long,i As Integer,n As String
Dim a(1 To 9)As String
Dim b(1 To 9)As String
Const num=“987654321”
For i=1 To 9
t=t*10+i
a(i)=space(i)+CStr(t) ‘CStr函数的功能是将数值转为字符,转换时不会添加空格
②
n=n+a(i)+“*8+”+CStr(i)+“=”+b(i)+Chr(13) ‘Chr(13)实现换行处理
Next i
Label1.Caption=n
End Sub
在程序中①画线处应填入;
在程序中②画线处应填人。
‘函数 bw 功能:若二进制位数不足,通过在前面添"0"使得位数为 4 的倍数
Private Function bw(x As Integer, y As String) As String
Dim r As Integer, i As Integer
r = x Mod 4
If r <> 0 Then
For i = 1 To 4 - r
y = “0” + y
Next i
x = Len(y)
End If
bw = ①
End Function
Private Sub Command1_Click()
Dim m As String, n As Integer, i As Integer, a As Integer
Dim s As Integer, s1 As String, j As Integer
m = Text1.Text
n = Len(m)
Text2.Text =“”
m = ② ‘调整m的位数为4的倍数
For i = 1 To n - 3 Step 4
s = 0
For j = i To i + 3
a = Val(Mid(m, j, 1))
s = ③
Next j
If s >= 10 Then
s1 = Chr(Asc("A") + s - 10)
Else
s1 = CStr(s) ‘函数CStr类似于 Str,但无前导空格
End If
Text2.Text = Text2.Text + s1
Next i
End Sub
① ② ③
For i=1 to 3
For j=1 to 5-i
If a(j)>a(j+1) Then
t=a(j) : a(j)=a(j+1) : a(j+1)=t
End If
Next j
Text1.Text = Str(a(i))+Text1.Text
Next i
数组元素a(1)到a(5)的值依次为“2,9,7,8,5”。若该程序段执行后,文本框Text1显示的内容是( )
Dim a(1 To 10)As Integer
Dim i As Integer, j As Integer
a(1)=1:a(2)=1
For i=3 To 5
a(i)=1
For j=i-1 To 2 Step-1
a(j)=a(j)+a(j-1)
Next j
Next i
Text1.Text=Str(a(3))
Private Sub Command1_Click( )
Dim i, n, tAs Integer
Dim m, s As Double
s=1:t=1
n=Val(Text1.Text)
For i=2 To n
m=1
For j=1 To ①
m= ② ‘计算1/(2*i-1)!
Next j
s=s+m*t ‘累加通项式
t=-t
Next i
Text2.Text=Str(s) ‘结果显示到文本框Text2中
End Sub
以上程序段运行时,为了实现上述功能,画线处应填入的代码分别为:①;②。
def fib(n):
a,b=1,1
for i in range(n):
a,b=b,a+b
return a
print(fib(5))
def fib(n):
#迭代求Fibonacci数列
f2=f1=1
for i in range(①,n+1):
②
return f2
n=int(input('输入需要计算的月份数:'))
print('兔子总对数为:',fib(n))
input("运行完毕,请按回车键退出...")
下列说法错误的是( )
Dim i As Integer, c As String, s As String, t As Integer
Dim s2 As String, pwd As String
s= Text1.Text: pwd = "71zhYEAR":s2= ":t= 0
For i= 1 To Len(s)
c= Mid(s, i, 1)
If c>= "0" Andc <= "9" Then
t=t* 10 + Val(c)
Else
s2 = s2 + Mid(pwd, tMod8 + 1, 1)
End If
Next i
Text2.Text= s2
运行该程序段,在文本框Text1中输入“20B13A8",文本框Text2输出的是( )
result = ""
s1 = Text1.Text
s2 = Text2.Text
i = 1
Do While i <= Len(s1)
If Mid(s1,i,Len(s2)) <> s2 Then
result = result + Mid(s1, i, 1)
i = i + 1
Else
i = i + Len(s2)
End If
Loop
在文本框Text1和Text2中分别输入“Pyyesthon”和“yes”,执行该程序段后,变量result的值是( )
Private Sub Form_Click( )
Dim i%, j%, k%, t% 't为统计素数的个数
Dim b As Boolean
For i = 100 To 200
b = True
k=
j = Int(Sqr(i))
Do While k <= j And b
If i Mod k = 0 Then
End If
Loop
if b=true then
t = t + 1
Form1.Print i
End If
Next i
Print "t="; t
End Sub
for num in range(2,10):
if num % 2==0 :
continue
print(num,end=”、”)
c = Text1.Text
s1 = "jiayou!" s2 = s1 + s1
For i =1 to len(s1)
If c = Mid(s2, i, Len(s1)) Then Exit For
Next i
Label1.Caption = Str(i)
程序执行完后,Label1中显示的内容是4,则Text1中输入的内容是( )
①next[p]= next[r] ②next[p]= r ③next[r]= p
④next[r]= -1 ⑤next[r]= next[p] ⑥next[p]= -1
y=0
x=1
while x<=10:
if x%5==0:
break
else:
y+=x
x=x+1
print(y)
Dim i As Integer, sum As Integer
Dim a(1 To 10) As Integer
sum=0
For i=1 To 10
a(i) = i+5
If a(i) Mod 3=0 Then sum=sum+a(i)
Next i
Text1. Text = Str(sum)
该程序段运行后,文本框Text1中显示的内容是( )
程序运行后,输入:8
运行结果是:
a=1
s=0
for i in range(1,5):
a=a*i
s=s+a
print(s)
运行结果是
①请填空,完善该程序实现功能:输入一串字符串(message)和一个数字(key)。对这串字符进行加密(向后移位Key位,只对26个英文字母加密)
注:程序修改时,请把下划线及序号删除,不能删除注释语句。
import math
import random
import os
#定义加密函数,对字母进行加密,即向后移动key位,其他字符不加密。
def cipher(befmessage, key):
aftmessage = ''
for char in befmessage:
if char.isupper(): #对大写字母进行加密
code = ord('A')+(ord(char)-ord('A')+key) % 26
aftmessage = aftmessage+chr(code)
elif char.islower(): #对小写字母进行加密
code = +(ord(char) - ord('a') + key) % 26
aftmessage = +chr(code)
else:
aftmessage = aftmessage+char #字母以外的其他字符不进行加密
return aftmessage
#主程序
message = input('请输入明文:')
key = (input('请输入密钥(整数):')) # 输入数字密钥
secret = cipher(message, )
print('加密后的密文是:',)
# 结束
②编写完成后,原名保存并关闭应用软件。