0
Task: print 5 table in this format: 5,10,15,20,25,30,35,40,45,50 using recursive funtion
Using python
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()
+ 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....
+ 6
Can you post your code here?
+ 5
Have you tried it yourself ? Could you please post your attempt ?
+ 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):"";
}
+ 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()
+ 2
Line 6: print(ml, end = ' ')
Does that make it look more like you want it?
+ 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()
+ 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()
+ 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()
+ 1
in 3hr 😅😅
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 .
0
Finally Done
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)
0
C is the answer
0
Thank you sm
- 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])?