Python 我可以写一个程序,可以重复x行数的图表吗
我在执行时遇到了一些问题。无法使其按我想要的时间循环。我的代码如下:Python 我可以写一个程序,可以重复x行数的图表吗,python,Python,我在执行时遇到了一些问题。无法使其按我想要的时间循环。我的代码如下: def question_6_2(): a = ['*','#','$'] b = [1,4,7] group1=(a[0]*b[0]+"\n") group2=(a[1]*b[1]+"\n") group3=(a[2]*b[2]+"\n") total_group=[group1,group2,group3]*i row_num=int(input("Please i
def question_6_2():
a = ['*','#','$']
b = [1,4,7]
group1=(a[0]*b[0]+"\n")
group2=(a[1]*b[1]+"\n")
group3=(a[2]*b[2]+"\n")
total_group=[group1,group2,group3]*i
row_num=int(input("Please input the number of rows you want: "))
for i in range(row_num+1):
print(total_group[i])
只是一个小改动-->print(总组[i])
到print(总组[i%3])
你的职能应该是:
def question_6_2():
a = ['*','#','$']
b = [1,4,7]
group1=(a[0]*b[0]+"\n")
group2=(a[1]*b[1]+"\n")
group3=(a[2]*b[2]+"\n")
total_group=[group1,group2,group3]
row_num=int(input("Please input the number of rows you want: "))
for i in range(row_num):
print(total_group[i%3])
question_6_2()
输出1:
Please input the number of rows you want: 10
*
####
$$$$$$$
*
####
$$$$$$$
*
####
$$$$$$$
*
请输入所需的行数:5
*
####
$$$$$$$
*
####
输出2:
Please input the number of rows you want: 10
*
####
$$$$$$$
*
####
$$$$$$$
*
####
$$$$$$$
*
请详述“一些执行问题”。上图是什么?它在哪里?谢谢你的指导!请问方括号中的%是多少?%=余数。既然你想以循环方式返回,那么最好使用模。假设你有list=
[1,2,3]
现在你说我想以循环方式返回(1->2->3->1->2->3->1)说7次。然后使用模数。当我变为3时,3%3=0,所以它将返回开始。如果i=4,4%3=1,则转到第1个位置,依此类推。