Skip to content

Instantly share code, notes, and snippets.

@iksaku
Created November 14, 2017 17:58
Show Gist options
  • Save iksaku/afc1a7ee9093d949bedafff8f0ce1740 to your computer and use it in GitHub Desktop.
Save iksaku/afc1a7ee9093d949bedafff8f0ce1740 to your computer and use it in GitHub Desktop.
Pythonista script for recursive summatory of consecutive numbers
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