Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. # 1. byrja spurja notanda um row og colum
  2.  
  3.  
  4. def seat_to_letter(seats):
  5. list_seats = ["A", "B", "C", "D", "E", "F"]
  6. if seats == 2:
  7. list_seats = list_seats[0:2]
  8. if seats == 4:
  9. list_seats = list_seats[0:4]
  10. if seats == 6:
  11. list_seats = list_seats[0:6]
  12. return list_seats
  13.  
  14.  
  15. def inp_to_dict(row, list_seats):
  16. my_dict = {}
  17. for i in range(1, row+1):
  18. my_dict[i] = list_seats
  19. return my_dict
  20.  
  21.  
  22. def print_rows(my_dict):
  23. for key, value in my_dict.items():
  24. print('{:2}\t'.format(key), end="")
  25. for k, seat in enumerate(value):
  26. if k % (len(value) / 2) == 0:
  27. print(" " * 1, end="")
  28. print("{} ".format(seat), end="")
  29. print()
  30.  
  31.  
  32.  
  33.  
  34. def book_seat_to_list(book_seat):
  35. my_list = []
  36. replace_list = []
  37. my_list.append(book_seat)
  38. for i in my_list:
  39. row, seat = i.split(" ")
  40. replace_list.append((row, seat))
  41. x = replace_list[0][0]
  42. y = replace_list[0][1]
  43. return x, y
  44.  
  45. def is_seat_taken(my_dict, x, y):
  46. if y == "A": # Allar if setninganar eru til þess að check hvar í listanum sætið er. t.d er sætið(breytan y) er A þá er það fyrsta stakið
  47. find = 0
  48. if y == "B":
  49. find = 1
  50. if y == "C":
  51. find = 2
  52. if y == "D":
  53. find = 3
  54. if y == "E":
  55. find = 4
  56. if y == "F":
  57. find = 5
  58. try:
  59. for key in my_dict:
  60. entries = my_dict[key]
  61. #print(key)
  62. #print(x,y)
  63. if key == int(x): # Ef lykilinn er sá sami og notandi stimplaði inn
  64. if entries[find] != "X": # Ef það er "X" á þeim stað í listanum
  65. pass
  66. except:
  67. print("Seat taken")
  68.  
  69.  
  70.  
  71.  
  72. def replace_seat(my_dict, x, y):
  73.  
  74. try:
  75. if int(x) in my_dict.keys():
  76. if y in [x for v in my_dict.values() for x in v]:
  77. my_dict[int(x)] = [i.replace(y, 'X') for i in my_dict[int(x)]]
  78. print_rows(my_dict)
  79. elif y not in [x for v in my_dict.values() for x in v]:
  80. print("Seat number is invalid!")
  81. else:
  82. print("Seat number is invalid!")
  83.  
  84. except:
  85. print("Seat number is invalid!")
  86. return my_dict
  87.  
  88.  
  89. def main():
  90. loop = True
  91. row = int(input("Enter number of rows: "))
  92. seats = int(input("Enter number of seats in each row: "))
  93. list_seats = seat_to_letter(seats)
  94. my_dict = inp_to_dict(row, list_seats)
  95. inp_to_dict(row, list_seats)
  96. seat_to_letter(seats)
  97. print_rows(my_dict)
  98.  
  99.  
  100. while loop:
  101. book_seat = input("Input seat number (row seat): ")
  102. x, y = book_seat_to_list(book_seat)
  103. is_seat_taken(my_dict, x, y)
  104. my_dict = replace_seat(my_dict, x, y)
  105. more = input("More seats (y/n)? ")
  106. if more == "n":
  107. loop = False
  108.  
  109.  
  110.  
  111. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement