# importing modules
import random
import numpy as np
action = ' ';
# define a function to showing current tasks
def show():
global text;
text = '';
quests = open('saves.txt', 'r')
lines = quests.readlines();
quests.close();
counter = 1;
if quests == []:
print ("You haven't quests now, it's time to add it.")
else:
for line in lines:
text = text + str(counter) + '. ' + line
counter+=1;
print (text);
# define a function to showing commands
def help():
print('''
What do you want to do? Enter a minimum first letter of command.
help — shows list of commands
show — to print not done quests
add — to add new quest in the list, enter "add#<quest content1>#<quest content2>"
done — to delete completed quest, enter "done#<quest_index>#<quest_index>"
exit — exit of program
generate — generate random task of list''');
# body of program
help();
while action[0] != 'e':
print();
print('Enter an action command: ');
action = input('> ');
print();
if action[0] == 'h':
help();
elif action[0] == 's':
show();
elif action[0] == 'd':
action = action.split('#');
action.remove(action[0]);
modifiedActions = [];
for element in action:
modifiedActions.append(int(element)-1);
quests = open('saves.txt', 'r')
lines = quests.readlines();
lines = np.delete(lines, modifiedActions).tolist();
quests.close();
print();
print ('Done!');
quests = open('saves.txt', 'w')
for line in lines:
quests.write(line);
quests.close()
show();
elif action[0] == 'a':
quests = open('saves.txt', 'a')
action = action.split('#');
action.remove(action[0]);
for element in action:
quests.write(element + '\n');
quests.close();
print();
print ('Done!');
show();
elif action[0] == 'g':
quests = open('saves.txt', 'r')
lines = quests.readlines();
quests.close();
print("So, let's go to do a quest...");
print(lines[random.randint(0, len(lines)-1)]);