0

Task: print 5 table in this format: 5,10,15,20,25,30,35,40,45,50 using recursive funtion

Using python

27th Nov 2018, 8:27 AM
ashish soni
ashish soni - avatar
17 Réponses
+ 11
Wow well done ashish soni !👏👏👍👍 Just a little thing to make it 1 line shorter 😉😉: def table(a,b=1,l=[]): if b>10: print("task done") else: ml=a*b l.append(str(ml)) if b==10: print(','.join(l)) return table(a,b+1,l) def main(): table(int(input("enter table no. "))) main()
27th Nov 2018, 9:17 AM
Uni
Uni - avatar
+ 7
Your code is good ashish soni only that you should write print with lowercase p. As for making it a list, sorry I can't help with that....
27th Nov 2018, 9:01 AM
Uni
Uni - avatar
+ 6
Can you post your code here?
27th Nov 2018, 8:37 AM
Uni
Uni - avatar
+ 5
Have you tried it yourself ? Could you please post your attempt ?
27th Nov 2018, 8:30 AM
Uni
Uni - avatar
+ 4
//here is a rough idea of doing that ● run recursion till largest multiple of 5 you want ● just do n*5 & add in previous one IF (n<desired number) [ie , calling same method again if n<(desired number) by doing increment in n by 1] //have a look at this sample code : //method call : System.out.print(met(1)); //recursive function definition : static String met(int a){ return a <11?a*5+"\n"+met(++a):""; }
27th Nov 2018, 8:48 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
Simpler but same result, I just modified your original code a bit: def table(a,b): if b==10: print(a*b,"\ntask done") else: print(a*b, end = ',') return table(a,b+1) def main(): table(int(input("enter table no. \n")),1) main()
27th Nov 2018, 11:36 AM
Paul
Paul - avatar
+ 2
Line 6: print(ml, end = ' ') Does that make it look more like you want it?
27th Nov 2018, 9:05 AM
Paul
Paul - avatar
+ 2
This one is too shorter bro... but i used that for user readable who are beginners... def table(a,b=1,l=[]): if b>10:print("task done") else:ml=a*b;l.append(str(ml)) if b==10:print(','.join(l)) return table(a,b+1,l) def main(): table(int(input("enter table no. "))) main()
27th Nov 2018, 11:06 AM
ashish soni
ashish soni - avatar
+ 1
def table(a,b): if b>10: Print("task done") else: ml=a*b print(ml) return table(a,b+1) def main(): table(int(input("enter table no. ")),1) main()
27th Nov 2018, 8:43 AM
ashish soni
ashish soni - avatar
+ 1
I acheive the target.. . see the code here : def table(a,b): if b>10: Print("task done") else: ml=a*b ml1=str(ml) l1.append(ml1) if b==10: print(','.join(l1) return table(a,b+1,l1) def main(): l1=[] table(int(input("enter table no. ")),1,l1) main()
27th Nov 2018, 9:16 AM
ashish soni
ashish soni - avatar
+ 1
in 3hr 😅😅
27th Nov 2018, 9:17 AM
ashish soni
ashish soni - avatar
0
My table is printing 5 10 15 20 25 30 35 . . 50 But i want that all no. Append in a list one by one after that i can use join funtion but my list is not creating .
27th Nov 2018, 8:34 AM
ashish soni
ashish soni - avatar
0
Finally Done
27th Nov 2018, 9:16 AM
ashish soni
ashish soni - avatar
0
But there is no option for (20, 35) a. (20,25,30,35,40) b. (20,25,30,35) c. (20,30) d. (20,30,40)
5th Oct 2021, 7:49 AM
Angelica Saha
0
C is the answer
5th Oct 2021, 7:49 AM
ashish soni
ashish soni - avatar
0
Thank you sm
5th Oct 2021, 7:52 AM
Angelica Saha
- 1
Given an object obj1= (5, 10, 15, 20, 25, 30, 35, 40, 45). What will be the output of print(obj1[3:7:2])?
5th Oct 2021, 7:38 AM
Angelica Saha