# Time traveler's tookit

hello I’m doing one of the new projects in python after the new update, its the Time Traveler’s Toolkit, back with other projects I just watch the walkthrough video and the YouTube explaind to me what was happening, I have no idea what todo after Task #7

here my code for example:
import datetime as dt

from decimal import Decimal

from random import randint, choice

import custom_module

today = dt.date.today()

time_now = dt.datetime.now().time()

#print(today)

#print(time_now)

base_cost = Decimal(100000*1)

print(base_cost)

1 Like

Hello! This is how i coded it. Not sure if it is the optimal approach but it works. Happy to have any feedback about how to improve it :

from datetime import datetime as dt
from decimal import Decimal
from random import randint
from random import choice
from custom_module import generate_time_travel_message

current_time = dt.today().year
→ Used today().year to retrieve just the current year to be able to use this code in any year, not just 2024.
#print(current_time)

base_cost = Decimal(“10.75”)
→ I set the base_cost to a random cost of 10.75.
current_year = Decimal(current_time)

#print(current_year)

random_year = randint(int(current_year), 10000)
→ I generated a random year between the current year and a settled year in the future and used int() to convert the variable current_year to an integer since randint requires integers as inputs.

cost_multiplier = abs(random_year - current_year)

time_travel_cost = base_cost * cost_multiplier
→ Multiplied base cost and cost multiplier to get a cost proportional to the number of years traveled.

final_cost = round(time_travel_cost, 2)
→ i rounded the final cost to two decimals.

destinations = [“France”, “Italy”, “Hawai”, “Australia”, “Denmark”, “Spain”, “Mars”]

random_destination = choice(destinations)

print(generate_time_travel_message(random_year, random_destination, final_cost))

Hope this helps

2 Likes

This helped me a lot! Thank you very much! Just to save space, when your importing the functions from random, you can do it in one line by separating the function names with commas. So instead, just write:

from random import randint, choice

Also, where you have “current_time = dt.today().year” that doesn’t work because you need to include the function name from the “datetime” module. “dt” is just the alias you defined for the datetime module, you still need to call the datetime function though. So, replace:
current_time = dt.today().year with
current_time = dt.datetime.today().year

I hope you find this useful

2 Likes

Thank you very much!!! It helped me and I hpe helps other!! also I realised that my problem was writing java script in python OMG LOL!! I was done with python and struggling with JS
but they updated the python course lol

1 Like

Here is the code. Of course, it could be improved, but if someone stuck maybe can help:
import datetime as dt

from decimal import Decimal

import random

from random import randint, choice

import custom_module

from custom_module import generate_time_travel_message

`current_date = dt.date.today()`

`current_time = dt.datetime.now().time()`

`print(f"Today is {current_date} and the right time is {current_time}")`

`current_year = dt.datetime.today().year`

(for testing purposes) print(current_year)

`base_cost = Decimal("2024.08")`

`random_year = randint(2025, 2124)`

(for testing purposes) print(random_year)

`cost_multiplier = abs(current_year - random_year)`

(for testing purposes) print(cost_multiplier)

`final_cost = round(base_cost * cost_multiplier, 2)`

(for testing purposes) print(final_cost)

`destinations = ["Paris", "Roma", "Berlin", "Bejing", "New York", "Los Angeles"]`

`selected_destination = choice(destinations)`

(for testing purposes) print(selected_destination)

`user_time_travel_experience = generate_time_travel_message(random_year, selected_destination, final_cost)`

2 Likes