fork download
  1. # importing modules
  2. import random
  3. import numpy as np
  4. action = ' ';
  5.  
  6. # define a function to showing current tasks
  7. def show():
  8. global text;
  9. text = '';
  10. quests = open('saves.txt', 'r')
  11. lines = quests.readlines();
  12. quests.close();
  13. counter = 1;
  14. if quests == []:
  15. print ("You haven't quests now, it's time to add it.")
  16. else:
  17. for line in lines:
  18. text = text + str(counter) + '. ' + line
  19. counter+=1;
  20. print (text);
  21.  
  22. # define a function to showing commands
  23. def help():
  24. print('''
  25. What do you want to do? Enter a minimum first letter of command.
  26.  
  27. help — shows list of commands
  28. show — to print not done quests
  29. add — to add new quest in the list, enter "add#<quest content1>#<quest content2>"
  30. done — to delete completed quest, enter "done#<quest_index>#<quest_index>"
  31. exit — exit of program
  32. generate — generate random task of list''');
  33.  
  34. # body of program
  35. help();
  36. while action[0] != 'e':
  37. print();
  38. print('Enter an action command: ');
  39. action = input('> ');
  40. print();
  41. if action[0] == 'h':
  42. help();
  43. elif action[0] == 's':
  44. show();
  45. elif action[0] == 'd':
  46. action = action.split('#');
  47. action.remove(action[0]);
  48. modifiedActions = [];
  49. for element in action:
  50. modifiedActions.append(int(element)-1);
  51. quests = open('saves.txt', 'r')
  52. lines = quests.readlines();
  53. lines = np.delete(lines, modifiedActions).tolist();
  54. quests.close();
  55. print();
  56. print ('Done!');
  57. quests = open('saves.txt', 'w')
  58. for line in lines:
  59. quests.write(line);
  60. quests.close()
  61. show();
  62. elif action[0] == 'a':
  63. quests = open('saves.txt', 'a')
  64. action = action.split('#');
  65. action.remove(action[0]);
  66. for element in action:
  67. quests.write(element + '\n');
  68. quests.close();
  69. print();
  70. print ('Done!');
  71. show();
  72. elif action[0] == 'g':
  73. quests = open('saves.txt', 'r')
  74. lines = quests.readlines();
  75. quests.close();
  76. print("So, let's go to do a quest...");
  77. print(lines[random.randint(0, len(lines)-1)]);
Runtime error #stdin #stdout #stderr 0.14s 24340KB
stdin
Standard input is empty
stdout
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

Enter an action command: 
> 
stderr
Traceback (most recent call last):
  File "./prog.py", line 39, in <module>
EOFError: EOF when reading a line