Sort as typed (python)

0

I have a problem with a problem that would be as follows, the problem asks to sort the numbers in the order that you typed them and then do the reverse order, someone can give me a light, the code is more or less this: p>

ps: is not in list.

this cont is because you have to show the media and how many were typed.

(I'm using the while true, pq in the problem it to quit qnd typing a negative number)

cont = 0
while True:
    notas = float(input("Informe a nota: "))
    if notas == -1:
        break
    cont += 1
print(cont)
    
asked by anonymous 22.04.2018 / 00:42

1 answer

0

It is really quite artificial to impose such an exercise and "try to use lists" because "it has not yet reached that part of the story".

If you happen to have "as part of the story" the manipulation of strings and the methods of strings, one way to do this is to concatenate all the values typed in a string, with a separator, and use the "split "to get the values back.

But the "for" in Python itself runs through elements of a list - which will be the return of the "split" function. I consider this form of teaching to be wrong . If you want, feel free to put this teacher in touch with me.

cont = 0
valores = ""
while True:
    nota_txt = input("Informe a nota: ")
    if float(notas_txt) == -1:
        break
    valores += notas_txt + ","
    cont += 1
for valor in valores[:-1].split(","):
    print(valor)
total = 0
for valor in reversed(valores[:-1].split(",")):
    print(valor)
    total += float(valor)

media = total / valores.count(",")
print("media:", media)
    
22.04.2018 / 05:57