Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bcc4378

Browse files
Merge branch 'avinashkranjan:master' into master
2 parents 2e81ed9 + 3e67658 commit bcc4378

File tree

15 files changed

+17149
-183
lines changed

15 files changed

+17149
-183
lines changed

‎Age_Calculator/Age_Calculator.py

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,30 @@
1-
# importing the date module from the datetime package
2-
from datetime import date
3-
4-
# defining a function calculate the age
5-
def calculate_age(birthday):
6-
7-
# using the today() to retrieve today's date and stored it in a variable
8-
today = date.today()
9-
10-
# a bool representing if today's day, or month precedes the birth day, or month
11-
day_check = ((today.month, today.day) < (birthday.month, birthday.day))
12-
13-
# calculating the difference between the current year and birth year
14-
year_diff = today.year - birthday.year
15-
16-
# The difference in years is not enough.
17-
# We must subtract 0 or 1 based on if today precedes the
18-
# birthday's month/day from the year difference to get it correct.
19-
# we will subtract the 'day_check' boolean from 'year_diff'.
20-
# The boolean value will be converted from True to 1 and False to 0 under the hood.
21-
age_in_years = year_diff - day_check
22-
23-
# calculating the remaining months
24-
remaining_months = abs(today.month - birthday.month)
25-
26-
# calculating the remaining days
27-
remaining_days = abs(today.day - birthday.day)
28-
29-
# printing the age for the users
30-
print("Age:", age_in_years, "Years", remaining_months, "Months and", remaining_days, "days")
31-
32-
# main function
33-
if __name__ == "__main__":
34-
35-
# printing an opening statement
36-
print("Simple Age Calculator")
37-
38-
# asking user to enter birth year, birth month, and birth date
39-
birthYear = int(input("Enter the birth year: "))
40-
birthMonth = int(input("Enter the birth month: "))
41-
birthDay = int(input("Enter the birth day: "))
42-
43-
# converting integer values to date format using the date() method
44-
dateOfBirth = date(birthYear, birthMonth, birthDay)
45-
46-
# calling the function to calculate the age of a person
47-
calculate_age(dateOfBirth)
1+
from datetime import date
2+
3+
def calculate_age(birthday):
4+
today = date.today()
5+
6+
# Check if the birthdate is in the future
7+
if today < birthday:
8+
return "Invalid birthdate. Please enter a valid date."
9+
10+
day_check = ((today.month, today.day) < (birthday.month, birthday.day))
11+
year_diff = today.year - birthday.year - day_check
12+
remaining_months = abs(today.month - birthday.month)
13+
remaining_days = abs(today.day - birthday.day)
14+
15+
# Return the age as a formatted string
16+
age_string = f"Age: {year_diff} years, {remaining_months} months, and {remaining_days} days"
17+
return age_string
18+
19+
if __name__ == "__main__":
20+
print("Simple Age Calculator")
21+
22+
try:
23+
birthYear = int(input("Enter the birth year: "))
24+
birthMonth = int(input("Enter the birth month: "))
25+
birthDay = int(input("Enter the birth day: "))
26+
dateOfBirth = date(birthYear, birthMonth, birthDay)
27+
age = calculate_age(dateOfBirth)
28+
print(age)
29+
except ValueError:
30+
print("Invalid input. Please enter valid integers for the year, month, and day.")

‎BMI-Calculator-GUI/README.md

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,62 @@
1-
<h1 align="center">BMI GUI Calculator</h1>
2-
Calculates Your Body Mass Index for your health fitness.
1+
# BMI GUI Calculator
32

4-
---------------------------------------------------------------------
3+
A graphical user interface (GUI) application that calculates your Body Mass Index (BMI) for assessing your health and fitness.
54

6-
## Modules Used
7-
- tkinter
5+
## Demo Image
86

9-
## How it works
10-
- It takes the given your Weight (kg) and Height (mts) as input.
7+
![Screenshot (1849)](https://github.com/mkswagger/Amazing-Python-Scripts/assets/34826479/c1407272-733e-4997-98de-b42d4406f59b)
118

12-
- It calculates the given input.
139

14-
- It returns Body Mass Index value, So you can check your health by the help of BMI chart.
1510

16-
#### By [Avinash Kr. Ranjan](https://github.com/avinashkranjan)
11+
## Functionality
12+
- Enter Weight: Use the slider to select your weight in kilograms.
13+
- Enter Height: Input your height in meters square in the provided text field.
14+
- Calculate BMI: Click the "Click to Check Your BMI" button to calculate your BMI.
15+
- Display Result: The calculated BMI value will be displayed below the button.
16+
- BMI Table: Refer to the BMI table on the right side for interpretation of the calculated BMI.
17+
## Libraries Used
18+
The following libraries were used in the implementation of this BMI calculator:
19+
20+
- Tkinter: Tkinter is the standard GUI toolkit for Python. It provides a set of Python bindings to the Tk GUI toolkit, allowing us to create graphical user interfaces.
21+
- math: The math library provides mathematical functions and constants. It is used in this calculator to perform the BMI calculation and round the result to two decimal places.
22+
23+
## How it Works
24+
1. **Input Weight and Height**: Enter your weight in kilograms (kg) using the provided slider. Then, input your height in meters (mts) in the text field.
25+
26+
2. **BMI Calculation**: The application calculates the BMI using the formula: BMI = weight / (height * height). The BMI value is calculated based on the weight and height inputs provided.
27+
28+
3. **BMI Result**: The calculated BMI value is displayed on the screen. The result is rounded to two decimal places.
29+
30+
4. **BMI Chart**: You can refer to the BMI chart to interpret your calculated BMI value and assess your health and fitness level.
31+
32+
## BMI Chart
33+
The BMI chart provides a general guideline for interpreting BMI values:
34+
35+
- Underweight: BMI less than 18.5
36+
- Normal weight: BMI between 18.5 and 24.9
37+
- Overweight: BMI between 25 and 29.9
38+
- Obesity Level I: BMI between 30 and 34.9
39+
- Obesity Level II: BMI between 35 and 39.9
40+
- Obesity Level III: BMI greater than or equal to 40
41+
42+
Note: The BMI calculation is a basic indicator and does not take into account factors such as muscle mass and distribution of fat. Consult a healthcare professional for a comprehensive evaluation of your health.
43+
44+
## How to Use
45+
46+
1. Clone the repository: `git clone https://github.com/your-username/bmi-calculator.git`
47+
2. Navigate to the project directory: `cd bmi-calculator`
48+
3. Install the required dependencies (Tkinter is usually included with Python).
49+
4. Run the application: `python bmi_calculator.py`
50+
5. Use the slider to select your weight in kilograms.
51+
6. Enter your height in meters in the provided text field.
52+
7. Click the "Click to Check Your BMI" button to calculate your BMI.
53+
8. The calculated BMI value will be displayed below the button.
54+
9. Refer to the BMI chart to interpret your BMI value and assess your health and fitness level.
55+
56+
57+
58+
## Requirements
59+
- Python (version 3.x)
60+
- Tkinter (usually included with Python)
61+
62+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /