What's new

Carl Robles

Forum Veteran
Elite
Joined
Sep 8, 2019
Posts
738
Solutions
12
Reaction
2,047
Points
690
339928398_926711601874902_4596300175150776573_n.png

how to make this code your life in weeks
 
To create a program that calculates how many weeks you've lived, you can start by asking the user for their birthdate. Then, you can use Python's datetime module to calculate the number of weeks between their birthdate and the current date.

Here's an example code:

Python:
import datetime

birthdate = input("Enter your birthdate in YYYY-MM-DD format: ")
birthdate_obj = datetime.datetime.strptime(birthdate, "%Y-%m-%d")

today = datetime.datetime.today()

weeks_lived = int((today - birthdate_obj).days / 7)

print("You have lived approximately {} weeks.".format(weeks_lived))

When you run this program and enter your birthdate, it will calculate the number of weeks you've lived and print it out.
 
To create a program that calculates how many weeks you've lived, you can start by asking the user for their birthdate. Then, you can use Python's datetime module to calculate the number of weeks between their birthdate and the current date.

Here's an example code:

Python:
import datetime

birthdate = input("Enter your birthdate in YYYY-MM-DD format: ")
birthdate_obj = datetime.datetime.strptime(birthdate, "%Y-%m-%d")

today = datetime.datetime.today()

weeks_lived = int((today - birthdate_obj).days / 7)

print("You have lived approximately {} weeks.".format(weeks_lived))

When you run this program and enter your birthdate, it will calculate the number of weeks you've lived and print it out.
your life in week using java script
 
your life in week using java script
To calculate your age in weeks using JavaScript, you can use the Date object to get the current date, and then ask the user for their birthdate. You can then calculate the difference between the two dates in milliseconds and convert it to weeks.

Here is an example code:

JavaScript:
let birthdate = prompt("Enter your birthdate (YYYY-MM-DD):");
let birthdateObj = new Date(birthdate);
let today = new Date();

// Calculate the difference in milliseconds
let differenceInMs = today.getTime() - birthdateObj.getTime();

// Convert the difference to weeks
let weeksLived = Math.floor(differenceInMs / (1000 * 60 * 60 * 24 * 7));

console.log(`You have lived approximately ${weeksLived} weeks.`);

When you run this code and enter your birthdate, it will calculate the number of weeks you've lived and print it out to the console.
 

Similar threads

Back
Top