diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..697e56f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.wav \ No newline at end of file diff --git a/Master_file.py b/Master_file.py new file mode 100644 index 0000000..d2a8fc0 --- /dev/null +++ b/Master_file.py @@ -0,0 +1,42 @@ +from playsound import playsound + +while True: + student_name = input("Insert the name of sudent: ") + student_name = student_name.lower() + student_name = student_name.capitalize() + + with open('Percatage_output.txt','a') as file_write: + with open('Percatage_output.txt') as file_read: + read = file_read.read() + if len(str(read))!=0: + file_write.write("\n") + file_write.write(f"{str(student_name)}\n") + + total_marks = 0 + subject_list = ['Maths','Hindi','English','Sst','Science'] + + for subject in subject_list: + while True: + try: + marks = float(input(f"Inset the mark of {student_name} in subject {subject}: ")) + if 0<=marks and 100>=marks: # Enter a number that is geater then 0 and smaller 100 then this sentex will break the while loop + break + else: + print("\tError: The marks must be between 0 and 100.") + playsound('Contents/Error.wav') + except ValueError: + print("\tError: The Insert Value must be a number.the") + playsound('Contents/Error.wav') + total_marks += marks + file_write.write(str(f" {subject}_{marks}\n")) + percentage = (total_marks / 500) * 100 + file_write.write(str(f"{student_name} got {'%.2f'% percentage}%\n")) + + if percentage>=60: + print(f"\t{student_name} got {'%.2f'% percentage}% and passed with first divison.\n") + elif percentage>=40: + print(f"\t{student_name} got {'%.2f'% percentage}% and passed with secound divison.\n") + elif percentage>=33: + print(f"\t{student_name} got {'%.2f'% percentage}% and passed with third divison.\n") + else: + print(f"\t{student_name} got {'%.2f'% percentage}% and {student_name} is fail\n") \ No newline at end of file diff --git a/Percatage_output.txt b/Percatage_output.txt new file mode 100644 index 0000000..40e6412 --- /dev/null +++ b/Percatage_output.txt @@ -0,0 +1,15 @@ +Pritam + Maths_96.0 + Hindi_89.0 + English_85.0 + Sst_72.0 + Science_91.0 +Pritam got 86.60% + +Aman + Maths_72.0 + Hindi_35.0 + English_56.0 + Sst_72.0 + Science_37.0 +Aman got 54.40% diff --git a/README.md b/README.md new file mode 100644 index 0000000..6589ed6 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# PERCENTAGE CALCULATOR :heavy_division_sign: + +### The function Percentage calculator asks the user for their marks in 5 subjects, calculate the percentage, and prints the result and provide the result in a Percentage_output.txt file. + +* Inside the function, we first initialize two variables: `total_marks` and `obtained_marks.` `Total_marks` represents the total number of marks that can be obtained for the 5 subjects, and `obtained_marks` represents the number of marks the user has obtained. We set `total_marks` to 0 and `obtained_marks` to 0 at the beginning, since no marks have been obtained yet. + +* Next, the program uses a for loop to iterate over the 5 subjects. For each subject, the user is prompted to enter their marks using the `input` function. The program then converts the user's `input` to an integer using the `int` function, since the `input` function returns a string. + +```python +total_marks = 0 +subject_list = ['Maths','Hindi','English','Sst','Science'] + +for subject in subject_list: + marks = float(input(f"Inset the mark of {student_name} in subject {subject}: ")) + total_marks total_marks + mark + file_write.write(str(f" {subject}_{marks}\n")) +``` + +* After the marks have been obtained, the program adds 100 to the `total_marks` (since each subject is worth 100 marks) and adds the user's marks to `obtained_marks`. This allows us to keep track of the total number of marks available and the number of marks the user has obtained. + +* After the for loop finishes, the program calculates the percentage by dividing `obtained_marks` by `total_marks` and multiplying the result by 100. This gives us the user's percentage as a decimal. + +* Finally, the program prints the percentage to the user using the `print` function and the `f` string format. The `f` string allows us to embed the value of the `percentage` variable directly into the string, so that the user can see their percentage. + +## THIS IS THE OUTPUT EXAMPLE OF *Percentage_output.txt* +![Percentage_output.txt](https://user-images.githubusercontent.com/84720825/210390900-c4122141-ba8a-4984-80d6-970e62b26e80.png) + +## INSTALLATION INSTRUCTIONS +### The easiest way to install this Percentage calculator: +1. Install [`Python compiler`](https://www.python.org/downloads/) :snake: on your local machine. +2. Clone this project or download this repo. +3. Delete all content of `Percentage_output.txt.` +4. Fire :fire: or run this command in bash to install a `External module` called [`Play sound.`](https://pypi.org/project/playsound/) +```bash +pip install playsound +``` +3. And you are good to go + +## KNOWN ISSUES +- [x] You have to use terminal to run this program. +- [ ] Currently not any *`GUI,`* **(Graphical user interface)** is Ceated for this project. \ No newline at end of file