Show on the screen the following operation with the tuple Tu: (ab)+(bc)+(cd)+(de)/e

Asked

Viewed 56 times

-3

Show on the screen the following operation with the tuple Tu:

(ab)+(bc)+(cd)+(de)/e  
tu=(10,20,30,40,50)  
a,b,c,d,e=tu  



print(ab)+(bc)+(cd)+(de)/e

  NameError                                 Traceback (most recent call last)  
  <ipython-input-28-342d00e3a09e> in <module>()  
  ----> 1 print(ab)+(bc)+(cd)+(de)/e  

NameError: name 'ab' is not defined  

Guys, how do I sum up tuples in parentheses? I’m a beginner in programming

  • 1

    To format the code, select it completely and hit the shortcut CTRL+K

  • ab should be the values appalled or multiplied?

  • 1

    In "dismayed", read concatenated.

1 answer

1

There are several ambiguities in the question that directly affect the solution.

The first is that we have no way of knowing for sure if the value ab must be the concatenation of values a and b, getting 1020, or if ab must be the product between a and b, getting 200. Whatever the correct form, your code is wrong.

  • If it’s concatenation, you need to convert to string and use the operator +: str(a)+str(b); or, in Python 3.6+ use f-string: f'{a}{b}';

  • If it’s multiplication, you need to use the operator *: a*b;

I spoke a little about the operators of Python in Which operator is equivalent to different in Python?

The second is that you put (ab)+(bc)+(cd)+(de)/e. That means, mathematically, that only the value de will be divided by e, which would only result in d, if e is other than zero.

As I believe right would be:

inserir a descrição da imagem aqui

You will need to put your entire denominator between parentheses: ((ab)+(bc)+(cd)+(de))/e.

Making these corrections, you will probably arrive at the expected result.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.