i=1
sum=0
while i<=20:
if I %2==0:
sum=sum-i
else:
sum=sum+i
i +=1
print (sum)
Dim i As Integer, a As Integer
i=6
a=6
If i <6 Then
a = a +4
Else
a = a -4
End If
在VB中有三种程序结构,其中的分支结构中有一种多分支结构,可以针对多种情况进行编程。在编写移动的坦克游戏中,其中有这一段代码
1 Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer) 2 Select Case KeyCode 3 Case 37 4 Image1.Picture = LoadPicure(App.Path& "\pic\tank1.jpg") 5 If Image1.Left - 20 < 0 Then 6 Image1.Left=0 7 Else 8 Image1.Left= Image1.Left-20 9 End If |
If a<=70 Then i=1
If a>70 Then i=2
Print i
以上程序段的执行结果为2。
a=int(input())
if :
print("7的倍数" )
else:
print("不是7的倍数")
m=int(input("请输入一个整数:"))
if ⑴:
print("这个数字是奇数")
⑵:
print("这个数字是偶数")
⑴A.m/2=0 B.m//2==0 C.m%2=0 D.m%2==1
⑵A.if B.else C.elif D.break
a=int(input("请输入a:"))
if a<0:
y=-a
else:
y=a
print(y)
输入: 2022
输出结果为
输入: -3
输出结果为
1)系统随机生成一个1~100的数字;
2)用户总共有5次猜数字的机会;
3)如果用户猜测的数字大于系统给出的数字,打印“too big";
4)如果用户猜测的数字小于系统给出的数字,打印"too small";
5)如果用户猜测的数字等于系统给出的数字,打印"恭喜",并且退出循环;
编写程序代码如下,请完善代码:
#导入random模块
#随机生成1-100的整数并赋值给变量game
time=5
while time>0:
guess=int (input ("请输入你所猜的数字:"))
if (guess>game) :
print ("too big")
elif :
print(" too small' )
else:
print ("恭喜”)
break
time=time-1
print("游戏结束,正确的结果是:",game)
Private Sub Command1_ Click()
a=Text2. Text '总评分
If a <75 Then
Label4. Caption ="★ 继续努力!"
Else
If a>90 Then
Label4. Caption ="★★★ 很棒!"
Else
Label4. Caption = "★★ 加油!"
End If
End If
End Sub
a=int(input("请输入1-20的整数"))
b=15
if a==b:
print("恭喜你,猜对了")
else:
if a>b:
print("很遗憾,猜大了")
else:
print("很遗憾,猜小了")