运行如图5的Python程序段,可以统计1,2, 3,4四个数字能够组成多少个互

练习题库2022-08-02  46

问题 运行如图5的Python程序段,可以统计1,2, 3,4四个数字能够组成多少个互不相同且**复数字的三位数。横线处应填语句是()A.inrange (1, 4)B.inrange (1, 5)B.in random.uniform (*, 4)D.in random.uniform (1, 5)

选项 A.inrange (1, 4)
B.inrange (1, 5)
B.in random.uniform (*, 4)
D.in random.uniform (1, 5)

答案 B

解析 本题考查编程基础,Python语言。
由题意。程序设计如下:
count=0#统计可以组成多少个数
my_ list=[]
for iin range (1, 5) :
forjin range (1, 5) :
fork inrange (1, 5) :
if (i!=j) and (i!=k) and Gj!=k) :
x= 100*i +10*j+k
my_ listappend (x)
print (x)
count= len (my_ list)
print (count)
运行结果:不相同且既重复数字的三位数共计24个,分别是: 123; 124; 132; 134; 142; 143; 213;
214; 231; 234; 241; 243; 312; 314; 321; 324; 341; 342; 412; 413; 421; 423; 431; 432。 [注: range (1, 5)是指循环1-4,不包含5]。故本题选B。
转载请注明原文地址:https://www.tihaiku.com/congyezige/1902252.html

最新回复(0)