Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1. byrja spurja notanda um row og colum
- def seat_to_letter(seats):
- list_seats = ["A", "B", "C", "D", "E", "F"]
- if seats == 2:
- list_seats = list_seats[0:2]
- if seats == 4:
- list_seats = list_seats[0:4]
- if seats == 6:
- list_seats = list_seats[0:6]
- return list_seats
- def inp_to_dict(row, list_seats):
- my_dict = {}
- for i in range(1, row+1):
- my_dict[i] = list_seats
- return my_dict
- def print_rows(my_dict):
- for key, value in my_dict.items():
- print('{:2}\t'.format(key), end="")
- for k, seat in enumerate(value):
- if k % (len(value) / 2) == 0:
- print(" " * 1, end="")
- print("{} ".format(seat), end="")
- print()
- def book_seat_to_list(book_seat):
- my_list = []
- replace_list = []
- my_list.append(book_seat)
- for i in my_list:
- row, seat = i.split(" ")
- replace_list.append((row, seat))
- x = replace_list[0][0]
- y = replace_list[0][1]
- return x, y
- def is_seat_taken(my_dict, x, y):
- if y == "A":
- find = 0
- if y == "B":
- find = 1
- if y == "C":
- find = 2
- if y == "D":
- find = 3
- if y == "E":
- find = 4
- if y == "F":
- find = 5
- try:
- for key in my_dict:
- entries = my_dict[key]
- #print(key)
- #print(x,y)
- if key == int(x):
- if entries[find] != "X":
- pass
- except:
- print("Seat taken")
- def replace_seat(my_dict, x, y):
- try:
- if int(x) in my_dict.keys():
- if y in [x for v in my_dict.values() for x in v]:
- my_dict[int(x)] = [i.replace(y, 'X') for i in my_dict[int(x)]]
- print_rows(my_dict)
- elif y not in [x for v in my_dict.values() for x in v]:
- print("Seat number is invalid!")
- else:
- print("Seat number is invalid!")
- except:
- print("Seat number is invalid!")
- return my_dict
- def main():
- loop = True
- row = int(input("Enter number of rows: "))
- seats = int(input("Enter number of seats in each row: "))
- list_seats = seat_to_letter(seats)
- my_dict = inp_to_dict(row, list_seats)
- inp_to_dict(row, list_seats)
- seat_to_letter(seats)
- print_rows(my_dict)
- while loop:
- book_seat = input("Input seat number (row seat): ")
- x, y = book_seat_to_list(book_seat)
- is_seat_taken(my_dict, x, y)
- my_dict = replace_seat(my_dict, x, y)
- more = input("More seats (y/n)? ")
- if more == "n":
- loop = False
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement