Decisión – Ejemplo 3

Enunciado

Se conoce la cantidad total de preguntas realizadas y la cantidad de respuestas correctas de un test de nivel para ingresantes a la facultad. Se pide informar el porcentaje de respuestas correctas y una leyenda que indique el nivel obtenido según:

Nivel 1 ===> Porcentaje >= 90%

Nivel 2 ===> 75% <= Porcentaje < 90%

Nivel 3 ===> 50% <= Porcentaje < 75%

Nivel 4 ===> Porcentaje < 50%

Código

Python

def main():
    ct = int( input( "Preguntas/Questions : " ) )
    cp = int( input( "Respuestas correctas/Correct answers : " ) )
    
    p = cp * 100 / ct
    print( "\n", p , "%" , end="" )

    if p>=90:
        print( " Nivel/Level 1 " )
    else:
        if p>=75:
            print( " Nivel/Level 2 " )
        else:
            if p>=50:
                print( " Nivel/Level 3 " )
            else:
                print( " Nivel/Level 4 " )

    input("Presionar/Press Enter to exit ")
main()

C++

#include <iostream>
using namespace std ;
#include <conio.h>

int main ()
{
   int  ct, cp ;
   float p ;
   	
   cout << "Preguntas/Questions : " ;
   cin >> ct ;
   cout << "Respuestas correctas/Correct answers : " ;
   cin >> cp ;
   	
   p = cp * 100 / ct ;
   cout << endl << p << "%" ;

   if ( p>=90 )
      cout << " Nivel/Level 1 " ;
   else
      if ( p>=75 )
      	 cout << " Nivel/Level 2 " ;
      else
         if ( p>=50 )
      	    cout << " Nivel/Level 3 " ;
         else
            cout << " Nivel/Level 4 " ;
   
   cout << "Presionar/Press Enter to exit " ;
   getch() ;
   return 0 ;
}

Pascal

Program Problema7_7 ;
var
    ct, cp : integer ;
    p : real ;

begin
    write( 'Preguntas/Questions: ') ;
    readln( ct ) ;
    write( 'Respuestas correctas/Correct answers: ') ;
    readln( cp ) ;
    
    p := cp * 100 / ct ; 
    write( p:0:2 , '%' ) ;

    if p>=90 
    then writeln( ' NIVEL/LEVEL 1 ' )
    else if p>=75 
         then writeln( ' NIVEL/LEVEL 2 ' )
         else if p>=50 
              then writeln( ' NIVEL/LEVEL 3 ' )
              else writeln ( ' NIVEL/LEVEL 4 ' ) ;
    
    writeln( 'Presionar/Press Enter to exit' ) ;
    readln ;
end.

Diagramas