Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Index + functions help
#1
I'm making a calculator on py, and that part don't work.
Someone can help me to make this work?
def ave():
    q = input('Coloca os numeros que serao usados para tirar a media entre espacos (ex: 0 1.2 -15)')
    n = q.split(' ')
    n = [float(i) for i in n]
    print(n)
    qq = len(n)
    print ('numeros escolhidos {}'.format(n))
    print ('quantidade de itens {}'.format(qq))
    w = 0
    while w<=qq:
        num = n[w]
        addS(num)
        w = w + 1
    if w == qq:
        print(ADDs)

ADDs = 0.0
def addS(x):
    global ADDs
    ADDs = ADDs + x
ave()
the error:
Traceback (most recent call last):
  File "/home/perrud/teste.py", line 21, in <module>
    ave()
  File "/home/perrud/teste.py", line 11, in ave
    num = n[w]
IndexError: list index out of range

Just to update, i make that work!!!
exd = 0
def EXD (x):
    global exd
    exd = exd + x

def ave():
    q = input('Coloca os numeros que serao usados para tirar a media entre espacos (ex: 0 1.2 -15)')
    n = q.split(' ')
    n = [int(i) for i in n]
    print(n)
    qq = len(n)
    for w in range(0,qq):
        EXD (n[w])
    global exd
    exd = (exd / qq)
    print(exd)
Reply
#2
Quote:and that part don't work.
Could you please elaborate?
Reply
#3
(Feb-04-2018, 05:11 PM)Larz60+ Wrote:
Quote:and that part don't work.
Could you please elaborate?
I have resolved dude. ^_^
The first code don't work.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020