Python While Looping Help

1

I have tried several times, I can print the largest amount, I can print the date of the biggest sale, my problem is at the time of the tie, code follows the loop like this in command, only when he wants, help me, spent hours trying find the error.

  
  • A record store records the number of discs sold each month during the month of March. Determine on what day of the month the biggest sale occurred and how many discs were sold that day.
  •   

    Follow the code:

    def main():
    
     qtd=int(input("Informe a quantidade"))
    
    valor=2
    
     i=1
    
     dia=0
    
     maior=0
    
     while i <=5:
    
     maior=qtd
    
     i = i + 1
    
     qtd = int(input("Informe a quantidade"))
    
     if maior > qtd:
    
     maior_qtd=maior
    
     dia=i-1
    
     maior_venda=maior_qtd*valor
    
     print("A maior venda foi {} ".format(maior_qtd))
    
     print("O valor da maior venda foi {}R$ ".format(maior_venda))
    
     print("A maior venda foi no dia {}/3".format(dia))
    
    
    main()
    

    Result:

    Informe a quantidade 9
    Informe a quantidade 4
    A maior venda foi 9 
    O valor da maior venda foi 18R$ 
    A maior venda foi no dia 1/3
    Informe a quantidade
    

    The loop is from 1 to 5 - and it only does two repetitions.

        
    asked by anonymous 17.07.2017 / 07:15

    1 answer

    1

    Indentation is missing from the code, but I will not judge you for it. Well, I read the question and developed something similar above and with comments for the explanation of some doubts.    I tried to be the most loyal to your code, I changed some variable names, I handled things a little differently. Study it and send feedback, please.

    OBS: "Determine on what day of the month the biggest sale occurred and how many discs were sold that day." So I did not put the value as in the case you put it, but that's it. It serves as the basis for study. Hugs brother!

    def main():
    # Definindo as variaveis
      maior_venda         = int
      dia                 = int
    
    # Atribundo Variaveis
      i           = 1 # Variavel que auxilia no ciclo
      maior_venda = 0 # maior venda == 0 pois não existe maior venda antes de vender algo.
    
      while i <= 5:
    
        qtd_vendida = int(input("Informe a quantidade de discos vendidos: ")) # Esse input trabalha com o ciclo, nao necessita de algo fora.
    
        if(qtd_vendida > maior_venda): # Verificamos se quantidade vendida e maior. Caso sim, atribua o valor a maior venda
            maior_venda = qtd_vendida #atribuimos a maior_venda a maior quantidade vendida
            dia = i # aqui ele verifica a posicao de i, caso quantidade vendida > que a maior venda anterior atribui a dia.
    
        i += 1; # adiciona +1 a variavel (i), controlando o ciclo.
    
      print("A maior quantidade de discos vendidos foi: {} discos".format(maior_venda))
      print("A maior quantidade de vendas foi feita dia: {}/MAR".format(dia))
    
    main()
    
      

    Test 1:       Enter the number of records sold: 25
          Enter the number of records sold: 10
          Enter the number of records sold: 50
          Enter the number of records sold: 39
          Enter the number of records sold: 40

          The largest number of records sold was: 50
          The highest amount of sales was done day: 3 / MAR

         

    Test 2:       Enter the number of records sold: 12
          Enter the number of records sold: 50
          Enter the number of records sold: 34
          Enter the number of records sold: 89
          Enter the number of records sold: 90

          The largest number of albums sold was: 90
          The biggest amount of sales was done day: 5 / MAR

        
    17.07.2017 / 08:32