Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Script finalnote


    Hi everyone
    I need your help to write the following script.
    thank you

    Write a Perl script that calculates noteFinale.pl literal note of a group of students.
    The data are provided to you in the file notes.csv. You must calculate the
    results and record ceuxci
    in the file note_finale.csv. Note literal is determined
    by the total of all the ratings and according to the following table:
    Note literal numeric score
    90 <= 100 A
    80 <= 89 B
    70 <= 79 C
    60 <= 69 D
    0 <= 59 E
    In addition, if a student gets literal note E, the reference should appear FAIL
    in the result file. The output file will contain the following information:
    the name and surname of the student;
    the notes in the order TP1, TP2, INRA, Final, Total;
    Note literal final
    identification of failure if applicable.
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,740
    Rep Power
    1959
    Think you forgot to add the script, can only see the description of your task (homework?).
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    Yes, this looks like a homework and it seems to be fairly simple.

    Please provide your attempt to do it by yourself and ask for help on any trouble you encounter. But don't ask for someone to do your assignment, that would really not help you in less short term, when you'll get a less simple one.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Hello
    I'm a beginner programming in perl. I don't know write in other file. Here's what I've done.
    thank you
    ***********
    #! usr/bin/perl -w
    use strict;
    system "clear";
    my @ligne;
    my $note;
    print "content type : fichier csv \n\n";
    open (FILE, "notes-1.csv")|| die ("Erreur");
    open (FIC, "> notes.csv")|| die ("Erreur");
    while (<FILE>){
    chomp;
    @ligne = split(",",$_);
    if ($. > 1){
    $note = $ligne[2]+$ligne[3]+$ligne[4]+$ligne[5];

    }

    }
    print FIL ($ligne[2],$note );
    close(FIC);
    close(FILE);
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by nizar75
    Hello
    I'm a beginner programming in perl. I don't know write in other file. Here's what I've done.
    thank you
    ***********
    #! usr/bin/perl -w
    use strict;
    system "clear";
    my @ligne;
    my $note;
    print "content type : fichier csv \n\n";
    open (FILE, "notes-1.csv")|| die ("Erreur");
    open (FIC, "> notes.csv")|| die ("Erreur");
    while (<FILE>){
    chomp;
    @ligne = split(",",$_);
    if ($. > 1){
    $note = $ligne[2]+$ligne[3]+$ligne[4]+$ligne[5];

    }

    }
    print FIL ($ligne[2],$note );
    close(FIC);
    close(FILE);
    the contents of the file fichier csv
    Nom,Prenom,tp1,intra,tp2,final
    Beethoven,Ludwig,25,22.25,20,23
    Mahler,Gustav,20,19.5,18.75,18.75
    Chopin,Frederick,14,15,17,12
    Straus,Richard,22,18.75,19,21.25
    Tchaikovsky,Pietor Ilitch,18.5,19.75,15,16
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    Yeah, it is much better to provide your attempt, which is not too bad and should more or less work up to the point you've got, except that you want to print out your result for each student, i.e. within the reading loop, not after.

    There seems to be an inconsistency between the assignment statement and your data: all marks seem to have a maximum value of 20 and you have only four of them. Even geniuses like Beethoven, Mahler of Chopin are unlikely to get an A or a B.

    All you still have to do is to find the literal score, to check for failure and print your results for each student, before reading to the next line (i.e. within the loop).

    The syntax to write to a file whose filehandle if FIC could be for example something like this:

    perl Code:
    print FIC "@ligne ", $literal_mark, " ", $note, "\n";


    Please tell if you have any other problem.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Thank you sir Laurent_R,
    I can execute the code now, but I have a problem
    I want priny in first line only the column names on the last line and the coma must separate columns.
    #! usr/bin/perl -w
    use strict;
    system "clear";
    my @ligne;
    my $note =0;
    my $mention;
    my $lateral ="";
    print "content type : fichier csv \n\n";
    open (FILE, "notes-1.csv")|| die ("Erreur");
    open (FIC, "> notes.csv")|| die ("Erreur");
    while (<FILE>){
    chomp;
    @ligne = split(",",$_);
    if ($. > 1){
    $note = $ligne[2]+$ligne[3]+$ligne[4]+$ligne[5];

    }
    if ($note >= 90 && $note <= 100){
    $lateral = "A";
    $mention = "";
    }

    elsif ( $note >= 80 && $note < 90 ) {
    $lateral = "B";
    $mention = "";
    }

    elsif ($note >= 70 && $note < 80) {
    $lateral = "C";
    $mention = "";
    }

    elsif ($note >= 60 && $note < 70) {
    $lateral = "D";
    $mention = "";
    }

    else {
    $lateral = "E";
    $mention = "echec";

    }
    print FIC "@ligne", "," , " ", $note, " ,", $lateral," ,", $mention ,"\n";
    }



    close(FIC);
    close(FILE);
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    If you want comma-separated values in your output, try to change:

    Code:
    print FIC "@ligne", "," , " ", $note, " ,", $lateral," ,", $mention ,"\n";
    to

    Code:
    my $output_line = join ", ", @ligne, $note, $lateral, $mention;
    print FIC $line, "\n";
    If you want to print the column names on the first line of your output, then print the line when you are testing whether it is the first line of input. Something like this:

    Perl Code:
    while (<FILE>){
        chomp;
        if ($. == 1) {
             print FIC $_, ", Total, Literal, Failed \n"; # prints input line + additional fields
         }
         else {
              @ligne = split(",",$_);
              $note = $ligne[2]+$ligne[3]+$ligne[4]+$ligne[5];
              # ...


    As a side note, it is today considered standard good practice to:

    - use the "use warnings;" pragma, rather than "-w" flag on the shebang line
    - use variable rather than bare words for file handler and use the 3 arguments syntax for opening a file, print the system error if any (the $! variable):

    Perl Code:
    open my $FILE, "<", "notes-1.csv" or die "Error opening notes-1.csv $! \n";
    open my $FIC, ">", "notes.csv" or die  Error opening notes.csv $! \n";
    while (<$FILE>){


    If you do so, of course you have to change FILE to $FILE and FIC to $FIC wherever they appear. And by the way, I would use variable such as $IN_FILE and $OUT_FILE, rather than $FILE ans $FIC, as descriptive variables names help avoiding mistakes.

    But, of course, if your instructor did not teach this way of opening files, you might prefer, for this assignment, to follow what you were shown to do.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Thank you very much, it's execute successfully, I have just a small bug, the code still display 0, E, echec at the first line (column name). I can't find the answer. You can help me.
    sincerly
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    Please provide the code that gives you this faulty output, as well as the exact output.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Hi
    You can give me your mail for send you my program.
    Thank you
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    Hi,

    just post the relevant part of your program and the relevant lines of output here.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    first part

    if ($. == 1) {
    print $FIC $_, ", Total, Literal, Mention \n"; # prints input line + additional fields
    }
    else {
    @ligne = split(",",$_);

    $note = $ligne[2]+$ligne[3]+$ligne[4]+$ligne[5];
    }

    second part

    my $output_line = join ", ", $note, $lateral, $mention;
    print $FIC $output_line , "\n";

    thank you for your help
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    Please provide the output which you consider to be faulty. So far, I do not understand where your problem is (and what it is).
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    at output I have
    nom, prenom, tp1, intra, tp2, total, lateral, mention
    0, E, echec
    My bug is 0, E, echec, I don't want to displaying this line.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo