Created
November 14, 2017 17:58
-
-
Save iksaku/afc1a7ee9093d949bedafff8f0ce1740 to your computer and use it in GitHub Desktop.
Pythonista script for recursive summatory of consecutive numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import console | |
def tryInput(prompt=None): | |
value = input(prompt) | |
try: | |
if int(value) <= 0: | |
raise ValueError | |
return int(value) | |
except ValueError: | |
print('Numbers should be integers, and here must be higher than Zero...') | |
return None | |
console.clear() | |
print(''' ( * * | |
)\ ) ( ` ( ` ( | |
(()/( ( )\))( )\))( )\ | |
/(_)) )\((_)()\((_)()((((_)( | |
(_)) _ ((_|_()((_|_()((_)\ _ )\ | |
| _ \ | | | \/ | \/ (_)_\(_) | |
| / |_| | |\/| | |\/| |/ _ \ | |
|_|_\\\___/|_| |_|_| |_/_/ \_\ | |
Welcome Human,''') | |
start = None | |
end = None | |
while start == None : | |
start = tryInput('Please tell me where to start: ') | |
while end == None: | |
end = tryInput('And when should I stop?: ') | |
print('\nSo, the number you\'re looking for, while summing from ' + str(start) + ' to ' + str(end) + ', is... ' + str(sum(range(start, end+1)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment