Created
April 5, 2020 15:26
-
-
Save andriiburka/ad9f92b3120e55971750ae0f2f8e173e to your computer and use it in GitHub Desktop.
My Final Exam of Python Fundamentals 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string = input() | |
while True: | |
command = input().split() | |
if "Done" in command: | |
break | |
elif "TakeOdd" in command: | |
temp = '' | |
for i in range(len(string)): | |
if i % 2 == 1: | |
temp += string[i] | |
string = temp | |
print(string) | |
elif "Cut" in command: | |
string = string[:int(command[1])] + string[int(command[1]) + int(command[2]):] | |
print(string) | |
elif "Substitute" in command: | |
if command[1] in string: | |
string = string.replace(command[1], command[2]) | |
print(string) | |
else: | |
print("Nothing to replace!") | |
print(f"Your password is: {string}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
for _ in range(int(input())): | |
match = re.match(r'@[#]+([A-Z][a-zA-Z0-9]{4,}[A-Z])@[#]+', input()) | |
if not match: | |
print('Invalid barcode') | |
else: | |
it_has_a_digits = "".join([char for char in match.group(2) if char.isdigit()]) | |
if it_has_a_digits: | |
print(f'Product group: {it_has_a_digits}') | |
else: | |
print(f'Product group: 00') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num_heroes = int(input()) | |
max_hp = 100 | |
max_mp = 200 | |
heroes_dict = {} | |
for i in range(1, num_heroes + 1): | |
name_hp_mp = input().split() | |
name = name_hp_mp[0] | |
hp = int(name_hp_mp[1]) | |
mp = int(name_hp_mp[2]) | |
heroes_dict[name] = {'hp': hp, 'mp': mp} | |
while True: | |
command = input() | |
if "End" in command: | |
break | |
command = command.split(' - ') | |
if "Heal" in command: | |
hero_name = command[1] | |
amount = int(command[2]) | |
if heroes_dict[hero_name]['hp'] + amount <= max_hp: | |
heroes_dict[hero_name]['hp'] += amount | |
print(f"{hero_name} healed for {amount} HP!") | |
else: | |
diff = max_hp - (heroes_dict[hero_name]['hp'] + amount) | |
new_amount = amount - abs(diff) | |
heroes_dict[hero_name]['hp'] = max_hp | |
print(f"{hero_name} healed for {new_amount} HP!") | |
elif "Recharge" in command: | |
hero_name = command[1] | |
amount = int(command[2]) | |
if heroes_dict[hero_name]['mp'] + amount <= max_mp: | |
heroes_dict[hero_name]['mp'] += amount | |
print(f"{hero_name} recharged for {amount} MP!") | |
else: | |
diff = max_mp - (heroes_dict[hero_name]['mp'] + amount) | |
new_amount = amount - abs(diff) | |
heroes_dict[hero_name]['mp'] = max_mp | |
print(f"{hero_name} recharged for {new_amount} MP!") | |
elif "TakeDamage" in command: | |
hero_name = command[1] | |
damage = int(command[2]) | |
attacker = command[3] | |
if not heroes_dict[hero_name]['hp'] - damage < 0: | |
heroes_dict[hero_name]['hp'] -= damage | |
print(f"Kyrre was hit for {damage} HP by {attacker} and now has {heroes_dict[hero_name]['hp']} HP left!") | |
else: | |
heroes_dict.pop(hero_name) | |
print(f"{hero_name} has been killed by {attacker}!") | |
elif "CastSpell" in command: | |
hero_name = command[1] | |
mp_needed = int(command[2]) | |
spell_name = command[3] | |
if mp_needed <= heroes_dict[hero_name]['mp']: | |
heroes_dict[hero_name]['mp'] -= mp_needed | |
print(f"{hero_name} has successfully cast {spell_name} and now has {heroes_dict[hero_name]['mp']} MP!") | |
for hero, value in heroes_dict.items(): | |
print(hero) | |
for i in value: | |
print(i[0]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment