Skip to content

Commit

Permalink
This is the version 1.00 of Percantage Calculater
Browse files Browse the repository at this point in the history
  • Loading branch information
pritam12426 committed Jan 4, 2023
0 parents commit 6ac73e8
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.wav
42 changes: 42 additions & 0 deletions Master_file.py
Original file line number Diff line number Diff line change
@@ -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")
15 changes: 15 additions & 0 deletions Percatage_output.txt
Original file line number Diff line number Diff line change
@@ -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%
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 6ac73e8

Please sign in to comment.