Please someone help to print function has to print numbers like Snack and ladder game when 2 variables rows and columns are passed to a function.
ex: fun(4,3)

12 11 10
7 8 9
6 5 4
1 2 3

Recommended Answers

All 3 Replies

I like using deque's appendleft for coding reverse sequence. You would of course use loops for row and column and eliminate the redundant statements here:

from collections import deque

ctr = 12

print_list = deque()
print_list.append(ctr)
ctr -= 1
print_list.append(ctr)
ctr -= 1
print_list.append(ctr)
ctr -= 1
print print_list

print_list = deque()
print_list.appendleft(ctr)
ctr -= 1
print_list.appendleft(ctr)
ctr -= 1
print_list.appendleft(ctr)
ctr -= 1
print print_list
def fun(var1, var2) : 
	count = 0
	main_list = []
	list1 = []
	for i in range(var1*var2, 0, -1) :
		if not i%var2 	:
			if not count%2 :
				list1.reverse()			
			list1.append('\n')
						
			main_list  =  main_list + list1
			list1 = []
			count = count + 1 
		list1.append(i)	
	list1.append('\n')
	main_list  =  main_list + list1
		
	for l in main_list :
		print l,

Please try not to give ready answers to homework questions and push Code button before pasting your code to message.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.