כתבתי ולא קיבלתי כלום חוץ ממסך שחור
יש שם משו שצריך לחפש באינטרנט והוא לא בחומר שנלמד.
זה קשור לאיזה סוג כתיבה עושים לקובץ
לייק 1
היי בנוגע למחברת 1 תרגיל 2 - לא כלכך הבנתי איך המשתמש מכניס קלט של שיר שמופרד בשורות?
למשל כמו הדוגמא שהבאתם:
עבור הקלט: “לילה לילה
מכה אפורה
האוטו שלנו” ואז “line”, יודפס: למה
את צודקת בתרגיל הזה, תניחי שלא המשתמש מכניס את הקלט
2 לייקים
לי זה נראה ככה לפני שעשיתי bytearray() על secret
אפשר עזרה ממישהו בתרגיל 1 מחברת 3 (עם התמונה) ?
(:
בטח אשמח לעזור (: (20)
import datetime
def update():
global cur_id
global lines
file.seek(0)
lines = file.readlines()
for i in range(len(lines)):
lines[i] = lines[i].strip().split(",")
if len(lines) > 1:
cur_id = int(lines[len(lines) - 1][0])
return
def openFile():
try:
file = open(fn, 'r+')
first_line = "ID,date,due_date,description,assignee,isdone\n"
file.write(first_line)
return file
except FileNotFoundError:
file = open(fn, 'w+')
first_line = "ID,date,due_date,description,assignee,isdone\n"
file.write(first_line)
return file
def userChoice():
msg = """Hey, you can choose from the following actions
1) Create a new task
2) Print a list of tasks, You can filter them later
3) Mark a task as done
4) Print a list of overdue tasks
5) Exit the program
Please insert the corresponding number only.\n
"""
while True:
inp = input(msg)
if inp.isnumeric():
if 6 > int(inp) >= 0:
return int(inp)
print("\nPlease Try Again\n")
def createTask():
task = []
temp = ""
task.append(cur_id + 1)
task.append(datetime.date.today().strftime('%d.%m.%Y'))
while True:
temp = input("What is the Due Date for the task?\n(Format:dd.mm.yyyy)\n")
valid = False
try:
datetime.datetime.strptime(temp, '%d.%m.%Y')
valid = True
except ValueError:
print("This isn't the correct format. Input needs to be dd.mm.yyyy\n")
if valid:
break
task.append(temp)
task.append(input("What is the task?\n"))
task.append(input("Insert Assignee name\n"))
task.append("False")
file.read()
file.write(str(tuple(task)).strip('()').replace("'","").replace(" ","").strip(","))
file.write("\n")
return
def filterAssignee():
name = input("By which assignee should I filter?\n(Enter name)\n")
global lines
print(*lines[0], sep=", ")
for line in lines[1:]:
if name == line[4]:
print(*line, sep=", ")
return
def filterDate():
while True:
temp = input("Enter input start date to filter by\n(Format:dd.mm.yyyy)\n")
valid = False
try:
datetime.datetime.strptime(temp, '%d.%m.%Y')
valid = True
except ValueError:
print("This isn't the correct format. Input needs to be dd.mm.yyyy\n")
if valid:
break
global lines
print(*lines[0], sep=", ")
for line in lines[1:]:
if temp < line[1]:
print(*line, sep=", ")
return
def filterStatus():
while True:
inp = input("Filter by finished tasks or unfinished?\n(insert: 'f' or 'u')\n")
if inp == 'u' or inp == 'f':
break
else:
print("INSERT ONLY 'f' or 'u'!!\n")
global lines
print(*lines[0], sep=", ")
if inp == 'u':
for line in lines[1:]:
if line[5] == "False":
print(*line, sep=", ")
elif inp == 'f':
for line in lines[1:]:
if line[5] == "True":
print(*line, sep=", ")
return
def printTask():
msg = """Print:
1) Every Task
2) Filter by Assignee
3) Filter by Date
4) Filter by status(Done or not)
5) Return to Main Menu
"""
while True:
inp = input(msg)
if inp.isnumeric():
inp = int(inp)
if 5 > inp > 0:
break
elif inp == 5:
return
print("\nPlease Try Again\n")
if inp == 1:
file.seek(0)
print(file.read())
elif inp == 2:
filterAssignee()
elif inp == 3:
filterDate()
elif inp == 4:
filterStatus()
return
def doneTask():
print("Great! You finished A task!\n")
file.seek(0)
print(file.read())
while True:
inp = input("\nWhich task did you finish?\n(insert task ID only)\n")
if inp.isnumeric():
inp = int(inp)
if inp == 0:
return
elif cur_id >= inp > 0:
global lines
lines[inp][5] = "True"
file.truncate(0)
file.seek(0)
for line in lines:
file.write(str(tuple(line)).strip('()').replace("'","").replace(" ","").strip(","))
file.write("\n")
file.flush()
return
print("\nPlease Try Again\n")
def printDueTasks():
global lines
print(*lines[0], sep=", ")
for line in lines[1:]:
if datetime.date.today().strftime('%d.%m.%Y') > line[1] and line[5] == "False":
print(*line, sep=", ")
return
def closeFile():
file.close()
return
def executeTaskManager():
global file
file = openFile()
update()
choice = userChoice()
while choice != 5:
if choice == 0:
file.seek(0)
print(file.read())
elif choice == 1:
createTask()
elif choice == 2:
printTask()
elif choice == 3:
doneTask()
elif choice == 4:
printDueTasks()
update()
choice = userChoice()
closeFile()
return
fn = "resources/tasks.csv"
file = ""
cur_id = 0
lines = []
executeTaskManager()