Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_valid(list, index):
- if 0 <= index < len(list):
- return True
- cards = input().split(', ')
- number_of_commads = int(input())
- for each_command in range(number_of_commads):
- command = input().split(', ')
- action = command[0]
- if action == 'Add':
- if command[1] in cards:
- print('Card is already in the deck')
- else:
- cards.append(command[1])
- print('Card successfully added')
- elif action == 'Remove':
- if command[1] in cards:
- cards.remove(command[1])
- print('Card successfully removed')
- else:
- print('Card not found')
- elif action == 'Remove At':
- index = int(command[1])
- if is_valid(cards, index):
- cards.pop(index)
- print('Card successfully removed')
- else:
- print('Index out of range')
- elif action == 'Insert':
- index = int(command[1])
- if is_valid(cards, index):
- if command[2] in cards:
- print('Card is already added')
- else:
- cards.insert(index, command[2])
- print('Card successfully added')
- else:
- print('Index out of range')
- print(*cards, sep=', ')
Advertisement
Add Comment
Please, Sign In to add comment