Jeremiah_

Menu.py

Jun 28th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.09 KB | None | 0 0
  1. class Menu:
  2.     def __init__(self):
  3.         self.mapeamento = -1
  4.         self.linhas_cache = -1
  5.         self.palavras_linha = -1
  6.         self.linhas_conjunto = -1
  7.         self.politica = -1
  8.         self.alg_subs = -1
  9.  
  10.     def le_mapeamento(self):
  11.         while True:
  12.             try:
  13.                 self.mapeamento = int(input('TIPO DE MAPEAMENTO\n1-Mapeamento Direto\n2-Mapeamento Associativo\n3-Mapeamento Associativo em Conjunto\n'))
  14.                 if self.mapeamento < 1 or self.mapeamento > 3:
  15.                     print('Digite apenas 1, 2 ou 3\n')
  16.                 else:
  17.                     break
  18.             except ValueError:
  19.                 print('Valor inválido!\n')
  20.  
  21.     def le_linhas_cache(self):
  22.         while True:
  23.             try:
  24.                 self.linhas_cache = int(input('NÚMERO DE LINHAS NA CACHE\n'))
  25.                 if self.linhas_cache < 1:
  26.                     print('O número de linhas na cache não pode ser menor que 1\n')
  27.                 else:
  28.                     break
  29.             except ValueError:
  30.                 print('Valor inválido!\n')
  31.  
  32.     def le_palavras_linha(self):
  33.         while True:
  34.             try:
  35.                 self.palavras_linha = int(input('NÚMERO DE PALAVRAS POR LINHA\n'))
  36.                 if self.palavras_linha < 1:
  37.                     print('O número de palavras por linhas não pode ser menor que 1\n')
  38.                 else:
  39.                     break
  40.             except ValueError:
  41.                 print('Valor inválido!\n')
  42.  
  43.     def le_linhas_conjunto(self):
  44.         if self.mapeamento == 3:
  45.             while True:
  46.                 try:
  47.                     self.linhas_conjunto = int(input('NÚMERO DE LINHAS POR CONJUNTO\n'))
  48.                     if self.linhas_conjunto < 1:
  49.                         print('O número de linhas por conjunto não pode ser menor que 1\n')
  50.                     else:
  51.                         if self.linhas_cache % self.linhas_conjunto != 0:
  52.                             print('O número de linhas na cache deve ser divisível pelo número de linhas por conjunto\n')
  53.                         else:
  54.                             break
  55.                 except ValueError:
  56.                     print('Valor inválido!\n')
  57.  
  58.     def le_politica(self):
  59.         while True:
  60.             try:
  61.                 self.politica = int(input('POLÍTICA DE ESCRITA\n1-Write through\n2-Write back\n'))
  62.                 if self.politica != 1 and self.politica != 2:
  63.                     print('Escolha 1 ou 2\n')
  64.                 else:
  65.                     break
  66.             except ValueError:
  67.                 print('Valor inválido\n')
  68.  
  69.     def le_alg_sub(self):
  70.         if self.mapeamento == 2 or self.mapeamento == 3:
  71.             while True:
  72.                 try:
  73.                     self.alg_subs = int(input('ALGORÍTIMO DE SUBSTITUIÇÃO\n0-FIFO\n1-Aleatório\n'))
  74.                     if self.alg_subs != 0 and self.alg_subs != 1:
  75.                         print('Escolha 0 ou 1\n')
  76.                     else:
  77.                         break
  78.                 except ValueError:
  79.                     print('Valor inválido!\n')
Advertisement
Add Comment
Please, Sign In to add comment