import re
import pandas as pd
import numpy as np
import random
tasks = set()
def main():
get_task()
get_time()
day_organization()
print_random_sentence()
def get_task():
global tasks
while True:
name_of_task = input("What is your task? ").strip()
if not name_of_task or re.search(r"\d", name_of_task):
print("You need to write a task(only with letters)")
continue
important = input("How match did the task important from Scale 0-10? ").strip()
if not important or 10 < int(important) or re.search(r"\D", important):
print("You need to write importance according to your task"
"(should be greater than or equal to 0 and less than or equal to 10")
continue
other = input("did you have other task. (yes or no)? ").strip().lower()
if other == "yes":
tasks.add((name_of_task, int(important)))
continue
else:
x = input("the answer need to be yes or no. what is your answer: ").strip().lower()
if x == "yes":
continue
else:
return tasks.add((name_of_task, int(important)))
def get_time():
global tasks
df = pd.DataFrame([{"Name_of_task": t[0], "Important": t[1]} for t in tasks])
df = df.sort_values(by="Important", ascending=False)
for index, row in df.iterrows():
print(f"Task: {row['Name_of_task']}, Importance: {row['Important']}")
while True:
importance = np.array(df["Important"])
time = input("How match time do you have for all of the tasks(in minutes)? ").strip()
if time:
time = float(time)
if len(df) == 1:
print(time)
else:
time_allocated = time * (importance / importance.sum())
df["Time_allocated"] = time_allocated
for index, row in df.iterrows():
print(
f"Task: {row['Name_of_task']}, Importance: {row['Important']}, Time needed: {row['Time_allocated']:.2f}")
break
if not time or re.search(r"^\D$", time):
continue
def day_organization():
global tasks
start_time = input("When do you want to start do your tasks? ").strip().lower()
print("DAY ORGANIZATION:")
print(start_time)
df = pd.DataFrame([{"Name_of_task": t[0], "Important": t[1]} for t in tasks])
df = df.sort_values(by="Important", ascending=False)
for index, row in df.iterrows():
print(f"Task: {row['Name_of_task']}")
def print_random_sentence():
sentences = [
"HAVE A GREAT DAY!",
"GOOD LUCK!",
"STAY FOCUSED AND KEEP GOING!",
"YOU'VE GOT THIS!",
"KEEP UP THE GOOD WORK!",
"YOUR PLAN IS READY, NOW GO FOR IT!",
"WISHING YOU A PRODUCTIVE DAY!"
]
print("\n" + random.choice(sentences))
if __name__ == "__main__":
main()
It works, but I’d like feedback on how to improve it.
How can I make the code more Pythonic and readable?
Are pandas and numpy the right tools here, or is there a simpler approach?
How can I organize the functions and handle user input more cleanly?