Addition is too basic for cool programmers, bringing a new python script for generating a function which effectively increments the value of an integer.
The script was inspired by a tweet from Pranay Pathole (@PPathole).
Tweet Link
script.py: Contains the actual code to generate the effective increment function.
effective.py: File generated by the script and has the actual function implemention.
Script can be executed either using command line arguments or input from stdin.
1st arg (argv[1]) is the base number to start from.
2nd arg (argv[2]) number of times the base number needs to be incremented.
script.py 10 20
In case command line arguments are not given, the script will ask you to enter them. The following message will appear on the terminal.
Either a base number or increment value was not passed
Enter base number: 10
Enter increment value: 20
Running the following command in terminal will generate a file called effective.py, make sure you don't have any other file with this name, chances are it may get overwritten by the script.
python script.py 7 11
effective.py
def effective_increment():
num = 7
if num == 7:
num = 8
if num == 8:
num = 9
if num == 9:
num = 10
if num == 10:
num = 11
if num == 11:
num = 12
if num == 12:
num = 13
if num == 13:
num = 14
if num == 14:
num = 15
if num == 15:
num = 16
if num == 16:
num = 17
if num == 17:
num = 18
return num
main.py
import effective
print(effective.effective_increment())
Automation is the future, with this script you can automate the basic task of incrementing a number. Further this script generates more code if the value to be incremented is large. More code means you can charge your client more (looks at COCOMO model). No need to use plus operator just import the effective.py file in your code and directly use the result from the function. Introduces modularity to your code, just like what you were taught in your Software Engineering class in college.