# 输入3个整数分别存储到变量a、b、c中,代码略
if a > b and a > c:
maxn = a
elif b > a and b > c:
maxn = b
elif c > a and c > b:
maxn = c
print("a,b,c的最大值为:", maxn)
执行该程序段,输入下列4组测试数据,无法正确输出a、b、c的最大值的是( )
A | B | C | D |
i=0 while i<=10: print(i) i=i+1 | i=10 while i>0: print(i) i=i-1 | for i in range(10): print(i) | for i in range(10,0,-1): print(i) |
a = int(input("请输入第一个数:"))
b = int(input("请输入第二个数:"))
k = 2
Lcd = 1
while a != 1 or b != 1:
if a % k == 0 or b % k == 0:
if
a = a // k
if
b = b // k
else:
print("最小公倍数为:", Lcd)
方框中的代码由以下四部分组成:
①Lcd = Lcd * k ②k = k + 1 ③b % k == 0 ④a % k == 0
则(1)(2)(3)(4)处代码顺序依次为( )
import random
a=[0,0,0,0,0,0]
for i in range(6):
x = random.randint(1, 10)
if i % 2 == 0:
a[i] = 2 * x + 1
elif x % 2 == 0:
a[i] = x // 2
else:
a[i] = x - 1
执行该程序段后,a[0]~a[5]各元素可能的值是( )
def isprime(n): #判断n是不是素数
for i in range():
if n%i==0:
else:
return True
def strsum(word): #统计单词的字母值总和
dic={"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,
"k":11,"l":12,"m":13,"n":14,"o":15,"p":16,"q":17,"r":18,"s":19,
"t":20,"u":21,"v":22,"w":23,"x":24,"y":25,"z":26}
n=0
for ch in word:
return n
word=input("请输入一个单词:")
s=strsum(word)
if flag:
print("这是一个素单词")
else:
print("这不是一个素单词")
A | 00001 | B | 00010 | C | 00011 | D | 00100 | E | 00101 | F | 00110 | G | 00111 |
H | 01000 | I | 01001 | J | 01010 | K | 01011 | L | 01100 | M | 01101 | N | 01110 |
O | 01111 | P | 10000 | Q | 10001 | R | 10010 | S | 10011 | T | 10100 | U | 10101 |
V | 10110 | W | 10111 | X | 11000 | Y | 11001 | Z | 11010 |
小明使用该编码对由大写字母组成的明文字符串进行加密,加密算法如下:
l依次将明文中每个字符转换为其对应的二进制编码;
l依次将密钥中每个字符转换为其对应的二进制编码;
l依次取出密钥的每个二进制位与原文的二进制位进行异或运算(若密钥长度不够,则循环重复使用),得到的结果即为密文编码;
l二进制位异或运算原则:11=0,00=0,10=1,01=1
例如,明文:HELLO,密钥:ZHE,则按上述方式进行加密:
明文字符 | H | E | L | L | O |
密钥字符 | Z | H | E | Z | H |
明文编码 | 01000 | 00101 | 01100 | 01100 | 01111 |
密钥编码 | 11010 | 01000 | 00101 | 11010 | 01000 |
密文编码 | 10010 | 01101 | 01001 | 10110 | 00111 |
def ctob(c): # 将一个字符转换为其对应的5位二进制编码
n =
ans = ""
for i in range(5):
r =
n = n // 2
ans = str(r) + ans
return ans
def xor(s1, s2): # 将二进制数s1和s2进行异或运算
ans = ""
for i in range(len(s1)):
if :
ans += "0"
else:
ans += "1"
return ans
s = input("请输入明文(大写字母):")
key = input("请输入密钥(大写字母):")
ans = ""
for i in range(len(s)):
s1 = ctob(s[i])
k =
s2 = ctob(key[k])
b = xor(s1, s2)
ans = ans + b
print("密文编码为:", ans)
# 输入n个数从小到大依次存储到列表nums中,代码略
k = -1
for i in range(n):
if nums[i] < 0:
k = i
else:
break
ans = []
i, j = k, k + 1
while i >= 0 or j < n:
if i < 0:
ans.append()
j += 1
elif j==n:
ans.append(nums[i] * nums[i])
elif :
ans.append(nums[i] * nums[i])
i -= 1
else:
ans.append(nums[j] * nums[j])
j += 1
print(ans)