Back

Explore Courses Blog Tutorials Interview Questions

Explore Tech Questions and Answers

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

0 votes
2 views
by (19.9k points)

I have two lists:

numbers =[2.4, 3.5, 0.5]

operations = ['+', '-']

Note that the values in operations will be changed so I cant just type:

solution = numbers[0] + numbers[1]

I need to insert the value of operations[0] between those numbers.

I've tried:

solution = numbers[0] + operations[0] + numbers[1]

But I can't merge floats and strings values.

1 Answer

0 votes
by (25.1k points)

Instead of using the string version of of the operator from operations list, you can use the operator module. Like this.

print(operators.add(numbers[0], numbers[1]))

Browse Categories

...