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

-3

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

(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  

Personal, how do I add tuples to parentheses? I'm a beginner in programming

    
asked by anonymous 27.09.2018 / 05:11

1 answer

0

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

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

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

  • If multiplying, you need to use the * operator: a*b ;

I talked a little bit about the Python operators in Which equivalent operator is different in Python?

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

How do I believe the correct one would be:

You will need to put all of your denominator in parentheses: ((ab)+(bc)+(cd)+(de))/e .

By making these fixes, you'll probably get the expected result.

    
27.09.2018 / 15:13