Not sure if it is possible but is there a way to multiply,add,or subtract values in a tuple? Say for example I have:

a=raw_input("enter 2 numbers separated by a /: ") #5/2 entered
b=a.split("/")
c=a[0]+a[1]
print c

The value comes out to 52 which is obviously wrong. Is their a way to specify that a[0] is int 5 instead of just the value 5?

You have to convert to int() or float().
If you concatenate two string then is just strings not numbers.

>>> '5' + '2'
'52'
a = raw_input("enter 2 numbers separated by a /: ") #5/2 entered
b = a.split("/")
c = int(b[0]) + int(b[1])
print c

You can also do it like this if you have a list with string.

>>> l = ['5', '2']
>>> [float(i) for i in l]
[5.0, 2.0]
>>> l = ['5', '2']
>>> map(int, l)
[5, 2]
>>> sum(float(i) for i in l)
7.0

Thank you very much! works perfectly!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.