# Day 47 100 day of code

At the end, the programme asks whether the player would like to play another round.
However, the answer ‘y’ aborts the programme.

The problem is somehow with the outer and inner loop

``````
import os, random, time

hero1 = 0
hero2 = 0
round = 0
r_hero1 = 0
r_hero2 = 0

heros = {
'Warrior': {'AC': 18, 'Speed': 30, 'Attack': 9, 'Magic': 2},
'Magican': {'AC': 12, 'Speed': 25, 'Attack': 3, 'Magic': 10},
'Rogue': {'AC': 15, 'Speed': 60, 'Attack': 8, 'Magic': 4},
'Cleric': {'AC': 16, 'Speed': 30, 'Attack': 6, 'Magic': 7},
'Paladin': {'AC': 17, 'Speed': 30, 'Attack': 7, 'Magic': 4},
'Ranger': {'AC': 14, 'Speed': 30, 'Attack': 8, 'Magic': 4}
}

def choose():
while True:
print('''
Welcome to the Character Creator!

1. Warrior
2. Magican
3. Rogue
4. Cleric
6. Ranger
''')
b = input('Press a number > ')
if b.isdigit() and int(b) in range(1, 7):
b = int(b)
if b == 1:
hero1 = 'Warrior'
elif b == 2:
hero1 = 'Magican'
elif b == 3:
hero1 = 'Rogue'
elif b == 4:
hero1 = 'Cleric'
elif b == 5:
elif b == 6:
hero1 = 'Ranger'
print('You chose:', hero1)
return hero1
else:
print('Invalid input. Please enter a number between 1 and 6.')
time.sleep(2)
os.system('clear')

def random_choose(li):
return random.choice(list(li.keys()))

while True:
hero2 = random_choose(heros)
hero1 = choose()
time.sleep(2)
os.system('clear')

while hero1 == hero2:
print('You both chose the same hero. Please choose again.')
hero1 = choose()
hero2 = random_choose(heros)
time.sleep(2)

while True:
print(f'The opponents are {hero1} and {hero2}')
print('1. AC')
print('2. Speed')
print('3. Attack')
print('4. Magic')
stat = input('Enter the number of the stat you want to choose: ')
if stat.isdigit() and int(stat) in range(1, 5):
stat = int(stat)
if stat == 1:
stat_name = 'AC'
elif stat == 2:
stat_name = 'Speed'
elif stat == 3:
stat_name = 'Attack'
elif stat == 4:
stat_name = 'Magic'
hero1_stat = heros[hero1][stat_name]
hero2_stat = heros[hero2][stat_name]
print(f'You chose {stat_name}.')
print(f'{hero1} has {stat_name}: {hero1_stat}')
print(f'{hero2} has {stat_name}: {hero2_stat}')
if hero1_stat > hero2_stat:
print(f'{hero1} wins with higher {stat_name}!')
r_hero1 += 1
round += 1
print(f'You played now Round {round}')
print(f'And you win {r_hero1} rounds')
elif hero1_stat < hero2_stat:
print(f'{hero2} wins with higher {stat_name}!')
r_hero2 += 1
round += 1
print(f'You played Round {round}')
print(f'And you win {r_hero2} rounds')
else:
print(f'Both heroes have the same {stat_name}. It\'s a tie!')
round += 1
break
else:
print('Invalid input. Please enter a number between 1 and 4.')

restart = input('Next round? (y/n): ')
if restart.lower() == 'y':
os.system('clear')
break  # Neustart der äußeren Schleife
elif restart.lower() == 'n':
print("***   Finish   ***")
exit()  # Beenden des Programms

``````

2 posts were merged into an existing topic: Day 047 - Project 47 : Top Trumps