Python programming (calculating average with shares, average case less than set value)

Asked

Viewed 293 times

-1

I need your help to solve an issue of my programming course, I have an initial activity and do not know where to continue, I need to create a program that gets 2 grades, disappear and divide by two generating the average. (I managed to do this) Now I need to implement the program if the student has the average less than 6 the program should request that a new test be done (I was able to print this message if the if is less than 6) only after this message it should give the following actions:

Action 1 if Note 3 is greater than Note 1 replaces Note 1 and sums up and divides with the rest.

Action 2 if note 3 is greater than note 2 replace note 2 and add and divide with the rest.

Action 3 if grade 3 is less than the two grades, display the failed student message.

Follow my code, I’m lost to be able to carry out these actions.

def main ():    

  nome = input('Nome do Aluno: ')
  ra = input('RA do aluno: ')
  print('Inserir notas de "0 a 10.0"')
  nota1 = float(input('Prova 1: '))
  nota2 = float(input('Prova 2: '))
  media = (nota1 + nota2) / 2
    
  if media > 6.0:
        print('O aluno ' , nome, 'de RA' , ra, 'foi Aprovado com a média ', media)
  else:
        nota3 = float(input('Aluno não passou, favor insirir nota da prova 3: '))
      
      
        maior1 = nota3
    
        if maior1 < nota1:
            maior1 = nota1
        if maior1 < nota2:
            maior1 = nota2
    
        if maior1 == nota3:
            if nota1 >= nota2:
                maior2 = nota1
        else:
            maior2 = nota2
    
        if maior1 == nota2:
            if nota1 >= nota3:
                maior2 = nota1
        else:
            maior2 = nota3
    
        if maior1 == nota1:
            if nota2 >= nota3:
                maior2 = nota2
        else:
            maior2 = nota3
    
        media = (maior1 + maior2)/2
        if media>= 6.00:
                print('O aluno ', nome, 'de RA ', ra, 'foi Aprovado com a média ', media, )
    
        else:
            print('O aluno ', nome, 'de RA ', ra, 'foi Reprovado com a média ', media, )
main ()

I thank you in advance for your help!

  • I believe you reversed the comparisons in your if with nota3 and the last condition must be if nota3 < nota1 and nota3 < nota2

  • I created a few more command lines, but I still face problems with the code. in the validation part

  • In the else is not to inform a condition. This elif media<6: has no sense because it will only be executed if media >= 6.0.

  • Well, I took a look and did not understand why the function, try to take it (if it is not requirement of exercise); has the reversed signs of conditions, as already commented; the first print after the condition is with the third note enclosed and will not read, will give error (I say from what I know so far, despite being a beginner); the last 2 prints are for the same thing, take one, ah and remember to indent in the right condition. See if it works there.

1 answer

0

One way to do it is with the use of Elif.

def main():
nome = input('Nome do Aluno: ')
ra = input('RA do aluno: ')
print('Inserir notas de "0 a 10.0"')
nota1 = float(input('Prova 1: '))
nota2 = float(input('Prova 2: '))
media = (nota1 + nota2) / 2

if media > 6.0:
    print('O aluno ' , nome, 'de RA' , ra, 'foi Aprovado com a média ', media)
else:
    nota3 = float(input('Aluno não passou, favor insirir nota da prova 3: '))

    #Com o uso do elif fica melhor de fazer, ja que ele só vai execultar quando o if for falso.
    if nota2 > nota1 < nota3:
        nota1 = nota3
    elif nota3 > nota2:
        nota2 = nota3

    media = (nota1 + nota2) / 2

    if media >= 6.00:
        print('O aluno ', nome, 'de RA ', ra, 'foi Aprovado com a média ', media, )

    else:
        print('O aluno ', nome, 'de RA ', ra, 'foi Reprovado com a média ', media, )

main()

Browser other questions tagged

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