[Solved]My approach on "Gapful numbers" problem. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[Solved]My approach on "Gapful numbers" problem.

I am not sure whether.. my approach is good or not. But any help will be appreciated. Thank you https://code.sololearn.com/c24sH0CNDKNk/?ref=app

25th Jun 2020, 6:06 PM
Sheikh Hafijul Ali
Sheikh Hafijul Ali - avatar
13 Answers
+ 1
Gapful Numbers: You can refer this codehttps://code.sololearn.com/cbmnK71jbl9f/?ref=app
25th Jun 2020, 6:57 PM
Suhail KM
+ 1
try: num=input() assert (abs(int(num))>=100) divisor=num[0]+num[-1] if abs(int(num))%int(divisor )==0: print(num,"is a gapful number") else: print(num,"is not a gapful number") except(ValueError,AssertionError): print("input must be integer atleast 3 digit long")
25th Jun 2020, 7:33 PM
Suhail KM
27th Jun 2020, 4:45 PM
Baratov Hojiakbar
Baratov Hojiakbar - avatar
0
Your approach is not good
25th Jun 2020, 6:57 PM
Suhail KM
0
suael Where is the problem.? is there any input that breaks my program?
25th Jun 2020, 6:59 PM
Sheikh Hafijul Ali
Sheikh Hafijul Ali - avatar
0
Problem 1:Gapful numbers not need to be always 3 digit number for example 1001 and -1001 are gapful numbers.. so your assert should be assert(abs(int(num))>100)..
25th Jun 2020, 7:04 PM
Suhail KM
0
suael okay.. missed that part thank you.
25th Jun 2020, 7:15 PM
Sheikh Hafijul Ali
Sheikh Hafijul Ali - avatar
0
i would say a good approach is to except value error and assertion error incase user enter a chaarcter string
25th Jun 2020, 7:16 PM
Suhail KM
0
suael have a look again on my code
25th Jun 2020, 7:19 PM
Sheikh Hafijul Ali
Sheikh Hafijul Ali - avatar
0
Yes, indeed i should, but...
25th Jun 2020, 7:22 PM
Sheikh Hafijul Ali
Sheikh Hafijul Ali - avatar
0
There is builtin abs function in python ..see above code ..
25th Jun 2020, 7:27 PM
Suhail KM
0
yes, there is.. but.. my code would require.. much more changes to use that way... i would find it difficult to print the divisor in my code.. and finally the initial input...
25th Jun 2020, 7:28 PM
Sheikh Hafijul Ali
Sheikh Hafijul Ali - avatar
0
this is not much change;.just make sure u make proper indentation for try and except
25th Jun 2020, 7:33 PM
Suhail KM