0

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

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by pyTony
0

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

Edited by woooee: n/a

0
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,

Edited by Nick Evan: Added CODE-tags

0

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

Edited by Reverend Jim: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.