Esta es el arreglo más correcta que encomtrarás aportar, pero obsérvala detenidamente y valora si se puede adaptar a tu trabajo.
Ejemplo: juego de troqueles de 2 platos en python
import random
defget_name(key):
n =""whilenot n:
n =input(f"Input your name, key: ")return n
defthrow_dice(key):
dices = random.choices(range(1,7),k=2)print(f"names[key] threw: dices", end =" ")ifsum(dices)%2==0:
score[key]+=10print("Even. You earn 10 points.")else:
score[key]-=5print("Odd. You loose 5 points")defprint_score():for n in score:print(f" names[n] has got score[n] points.")defwin_message(s,n):
print_score()if score["P1"]> score["P2"]:print(f"names['P1'] won")else:print(f"names['P2'] won")
player =""
score =
names =for n in["P1","P2"]:
names[n]= get_name(n)
score[n]=0# twice the amount of rows wanted, because players take turnfor c inrange(10):# switches between player1 and player2
player ="P1"if player !="P1"else"P2"print(f"Round c//2+1: it is names[player]'s turn.")
print_score()
throw_dice(player)
win_message(score,names)
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)