r/programmingrequests • • Dec 15 '17

[REQUEST] Modify the said program below

def main():
num = input('Enter a number 1 - 9,999,999: ')

try:
    num = str(int(num))
except Exception:
    print('not a number')
    return

assert 1 <= int(num) <= 9999999, 'not in range'

print(num)

while len(num) > 1:
    last, second_last = (int(n) for n in num[-2:])
    num = num[:-2] + str(last + second_last)
    print(num)


if __name__ == '__main__':
main()

here's an example run:

Enter a number 1 - 9,999,999: 50123
50123
5015
506
56
11
2

Hi, Would anyone be able to modify the program above, that after it displays the break numbers it will prompt me to enter 1 to 100 and then example I enter 26 it will give the possible results how it got 26 using only the given break numbers. Please include the main 9541 number in the computation not just after it breaks it. Please have the program not use the same number all over again if it has used two 9's it is left with only two more 9's as when you break 9541 it has four 9's when we break it. This goes with the rest of the numbers (no repeat) I mean.

Example: I break the number 9541 gives the results below:

9541 
955 
910 
91 
10 
1

The display of the result would be liked example -

Enter numbers from 1 to 100:  26

9541 
5 
1 
1 
=========================
9+5+4+1+5+1+1 = 26 

and so on. ( can use any operator +, - , * , /) as long as it gets 26 results

after this is done it will go backs to a loop and ask me to enter 1 to 100 again: I enter 30

it displays how he get's 30 but uses the remaining number available the program cannot repeat any number being used from previous number 26

if the number I entered will not be possible like it will just display FALSE and loops back again asking me to enter another number from 1 to 100.

I hope that I have explained clearly what I require.

Thank you very much :)

NOTE: I DO NOT OWN THE PROGRAM ABOVE EVERYONE CAN USE IT.

2 Upvotes

2 comments sorted by

1

u/bokibaby24 Dec 18 '17

Hi Harold, I am getting error when I ran the program im using Python 3.4.3

 Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
 Type "copyright", "credits" or "license()" for more information.
 >>> ================================ RESTART ================================
 >>> 
 Enter a number from 1 to 9,999,999: 9614
 9614
 965
 911
 92
 11
 Traceback (most recent call last):
 File "C:/Users/Boki/Desktop/SplitNumber+AddingSplitNumbers.py", line 19, in <module>
 num_list.remove(0)
 AttributeError: 'map' object has no attribute 'remove'
 >>> 

1

u/[deleted] Dec 17 '17 edited Dec 17 '17

https://pastebin.com/raw/EKcDDfTv

Edit: this isn’t completely proofed out, but it’s late for me. I might try more tomorrow.