vendredi 28 juin 2019

How can I make an if and elif statement based on an outcome of random.choice and an input

I am trying to create a game that asks you what a certain character does in a book and I am using random.choice and an if and elif statement to do that however when I type my input to answer the question the output is always wrong even though i answered the question wright.

I have tried to make the if statement:

if 'The main character' in card_list and choice == person1:
  print("correct")

for every statement however the results are always correct even if i type in the wrong answer.

import random

card1 = 'The main character'
card2 = 'He brings aleem on holiday'
card3 = 'Dies in the middle of the book'
card4 = "She takes care of aleem while aleem's dad is in Ethiopia"
card5 = 'He helps take care of aleem with Miss Fitzgerald'
card6 = "He is in charge of aleem's court case"

person1 = 'aleem'
person2 = "aleem's dad"
person3 = "aleem's mum"
person4 = 'Miss Fitzgerald'
person5 = 'Mr Fitzgerald'
person6 = 'Nicolas'

card_list = [card1, card2, card3, card4, card5, card6]

print(random.choice(card_list))

choice = input('Who is this? ')

if 'The main character' == random.choice and choice == person1:
  print("correct")
elif 'He brings aleem on holiday' == random.choice and choice == 
person2:
  print('correct')
elif 'Dies in the middle of the book' == random.choice and choice == 
person3:
  print('correct')
elif "She takes care of aleem while aleem's dad is in Ethiopia" == 
random.choice and choice == person4:
  print('correct')
elif 'He helps take care of aleem with Miss Fitzgerald' == 
random.choice and choice == person5:
  print('correct')
elif "He is in charge of aleem's court case" == random.choice and 
choice == person6:
  print('correct')
else:
  print('wrong')

This is what I have been using to create the game.

Aucun commentaire:

Enregistrer un commentaire