d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Simple Addition "program/tool"
12Next
Add Reply New Topic New Poll
Member
Posts: 6,504
Joined: Jun 18 2007
Gold: 13,428.00
Dec 12 2014 08:43pm
I need something that can add up 10 numbers like this

example 1 1 1 6 4 8 4 10 5 9

If i could copy and past the numbers into something that automatically do it that would be great
or something that replaces the spaces with addition symbols + would work

It has to operate faster then i could do it mentally :D granted I'm not that fastest at mental math

I'm not familiar with excel but could this be done in excel?

This post was edited by MW_Dream on Dec 12 2014 08:45pm
Member
Posts: 6,504
Joined: Jun 18 2007
Gold: 13,428.00
Dec 12 2014 08:52pm
this might be useful i have no idea :wallbash:

http://www.javascriptkit.com/script/cut42.shtml

Member
Posts: 62,215
Joined: Jun 3 2007
Gold: 9,039.20
Dec 12 2014 10:02pm
https://www.python.org/download/releases/3.0/

Code
#!/usr/bin/env python

def addr(n):
o = [int(e) for e in n.split(' ')]
return sum(o)

while addr:
try:
n = input('')
addr(n)
except ValueError:
print('oops, don't start with space or anything dum')


Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Dec 12 2014 11:19pm
Code
public class shit {
static double piss(String numbers) throws NumberFormatException {
double sum = 0;
for (String s : numbers.split(" ")) {
sum += Double.parseDouble(s);
}
return sum;
}

public static void main(String[] args) {
try {
System.out.println(piss("1 1 1 6 4 8 4 10 5 9"));
} catch (NumberFormatException e) {
System.out.println("shit happend");
}
}
}
Member
Posts: 6,504
Joined: Jun 18 2007
Gold: 13,428.00
Dec 15 2014 06:53pm
Quote (killg0re @ Dec 12 2014 11:02pm)
https://www.python.org/download/releases/3.0/

Code
#!/usr/bin/env python

def addr(n):
  o = [int(e) for e in n.split(' ')]
  return sum(o)

while addr:
  try:
        n = input('')
        addr(n)
  except ValueError:
        print('oops, don't start with space or anything dum')


https://i.imgur.com/r0Lrz1n.png


He explained this via messages, but im still confused. Can anyone explain what he means in this message


Code
Yeah, you copy what I wrote into a file and save it as add.py or whatever you want to call it.

With Python installed you open up Command then change the directory to where you saved the file

cd C:\Users\MW_Dream\Desktop

Then type in python add.py

Now when you copy spaced numbers into Command then press [Enter] you should receive the answer, lol.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 15 2014 07:06pm
Quote (MW_Dream @ Dec 15 2014 07:53pm)
He explained this via messages, but im still confused. Can anyone explain what he means in this message


Code
Yeah, you copy what I wrote into a file and save it as add.py or whatever you want to call it.

With Python installed you open up Command then change the directory to where you saved the file

cd C:\Users\MW_Dream\Desktop

Then type in python add.py

Now when you copy spaced numbers into Command then press [Enter] you should receive the answer, lol.


which part do you not get?

if you're on mac/linux, use the terminal instead of command prompt.
Member
Posts: 6,504
Joined: Jun 18 2007
Gold: 13,428.00
Dec 15 2014 08:27pm
Quote (carteblanche @ Dec 15 2014 08:06pm)
which part do you not get?

if you're on mac/linux, use the terminal instead of command prompt.


I'm on windows

I downloaded python

made the add.py file on my desktop with his code.

Just don't get what to do from here
Member
Posts: 6,504
Joined: Jun 18 2007
Gold: 13,428.00
Dec 15 2014 08:44pm
"With Python installed you open up Command then change the directory to where you saved the file"

Am i opening "command line" python or CMD.

Am i changing the directory of python? or the directory of the add.py

What am i changing the directory to? and why

postimg.org/image/ju48lwoot

This post was edited by MW_Dream on Dec 15 2014 08:56pm
Member
Posts: 6,504
Joined: Jun 18 2007
Gold: 13,428.00
Dec 15 2014 09:38pm
Ok i think i understand it a little now using cd "C:/Users/Charles/Desktop" I just to navigate in CMD to that area to execute the add.py file.

However after i navigate to desktop in cmd and then type "python add.py"

this is what i get

http://imgur.com/v5PZZCh

Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Dec 15 2014 10:14pm
I went ahead and whipped up a tool for you as well. This is just one of a couple derivatives I have created for other people here on d2jsp.

It is an extension of the base application framework, which I will give you first.

Code
package NumberReader;

public interface INumberReader
{
void readNumbers();
}

Code
package NumberReader;

import java.io.InputStream;
import java.io.PrintStream;

public interface INumberReaderConfig
{
Number getMaximumNumber();
Number getMinimumNumber();
int getAmountOfNumbers();
InputStream getInputer();
PrintStream getPrinter();
}

Code
package NumberReader;

public interface INumberReaderFactory
{
INumberReader createNumberReader(INumberReaderConfig config);
}
Code
package NumberReader;

public class NumberNotFoundException extends RuntimeException
{
public NumberNotFoundException(String msg)
{
super(msg);
}
}

Code
package NumberReader;

public abstract class NumberReaderApplicationBase
{
private INumberReaderFactory numberReaderFactory;
private INumberReaderConfig numberReaderConfig;

public NumberReaderApplicationBase(INumberReaderFactory numberReaderFactory, INumberReaderConfig numberReaderConfig)
{
this.numberReaderFactory = numberReaderFactory;
this.numberReaderConfig = numberReaderConfig;
}

public void execute()
{
INumberReader nr = numberReaderFactory.createNumberReader(numberReaderConfig);

nr.readNumbers();
}
}

Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll