vendredi 4 septembre 2020

If statements with random choice not working [closed]

I’m wanting to create a baseball text simulation game in python and have started to work out some ideas. I have some lists that have options in them and am running if statements to pass through the lists to get a desired outcome. Code:

import random

def rand(x):
  random.choice(x)

outcome = ['ballzone', 'strikezone']
ball_zone = ['swing', 'take']
strike_zone = ['swing', 'take']
swing = ['hit', 'foul']

first_pitch = random.choice(outcome)

if first_pitch == 'ballzone':
  if rand(ball_zone) == 'swing':
    print(rand(swing))
  elif rand(ball_zone) == 'take':
    print('BALL ONE')
elif first_pitch == 'strike_zone':
  if rand(strike_zone) == 'swing':
    print(rand(swing))
  elif rand(strike_zone) == 'take':
    print("STRIKE ONE")

When I run this code, it doesn’t have an output or result. I don’t know if I’m doing something wrong or if I’m missing something. Any help will be greatly appreciated. Thanks.

Aucun commentaire:

Enregistrer un commentaire