Ask coding questions

← Back to all posts
HELP ME!
crazyCoder691 (6)

I have this list

ai_options["attack, heal"]
abcd = random.choice(AI_options)
print("The chosen was: {}".format(abcd))

This works fine and prints one of the options but what I want it to do is this:

import random
ai_options["attack, heal"]
abcd = random.choice(AI_options)
if attack is chosen:
    do this
elif heal is chosen:
    do this other thing

Does anybody have any solutions?? Solved By @Highwayman
answer:

import random
ai_options["attack, heal"]
abcd = random.choice(AI_options)
if abcd == "attack" :
  do this
elif abcd == "heal" :
  do this other thing
Answered by Highwayman (1250) [earned 5 cycles]
View Answer
Commentshotnewtop
Highwayman (1250)

so, for you question;

How about

import random
ai_options["attack, heal"]
abcd = random.choice(AI_options)
if abcd == "attack" :
  do this
elif abcd == "heal" :
  do this other thing
crazyCoder691 (6)

Thanks @Highwayman this really worked!

Highwayman (1250)

Also as a side note: you can use
~ name_of_lamguage
CODE
~

To make the code be highlighted properly and everything in repl.it posts

Edit sorry one sec thing isn’t showing.

Highwayman (1250)

Post this in ask and you shall receive help. This is for sharing finished work, not asking questions
Edit: sorry not for sharing finished stuff, for sharing tutorials.

crazyCoder691 (6)

Thank you @Highwayman! I was able to finish my game(with the help of one of my cousins) FIGHT!!