-1

Apparently I've made a lot of mistakes, I'm pretty new to Python so that's why.

I have a random.randint within an if statement and another one within an elif statement. But the 1st one comes up even when I put my input to an answer that's supposed to take me to the second one (E.g. prank).

This is my code:

import random
LOL = raw_input('Do you want a meme or a prank idea? ')
if LOL == 'meme' or 'Meme' or 'MEME':
x = random.randint(1, 5)
    if x == 1:
        print('Yee')
    elif x == 2:
        print('Yeet!')
    elif x == 3:
        print('I got the horses in the back')
    elif x == 4:
        print('AND HIS NAME IS JOHN CENA!!!!')
    elif x == 5:
        print('IT\'S OVER 9000!')
  elif LOL == 'prank' or 'Prank' or 'PRANK':
        y = random.randint(1, 3)
    if y == 1:
        print('Replace their Oreo frosting with toothpaste.')
    elif y == 2:
        print('Blast into their room with an air horn.')
    elif y == 3:
        print('Blast the FBI meme on a loud speaker on max volume')

It shows the one of the memes even when I write "prank" and I think it's because the random.randint goes anyways and since it's first, it goes first and overlaps the second random.randint.

3 Answers3

0

You are using or operator in the wrong way

Try this:

import random
LOL = raw_input('Do you want a meme or a prank idea? ')
if LOL == 'meme' or LOL == 'Meme' or LOL == 'MEME':
  x = random.randint(1, 5)
  if x == 1:
    print('Yee')
  elif x == 2:
    print('Yeet!')
  elif x == 3:
    print('I got the horses in the back')
  elif x == 4:
    print('AND HIS NAME IS JOHN CENA!!!!')
  elif x == 5:
    print('IT\'S OVER 9000!')
elif LOL == 'prank' or LOL == 'Prank' or LOL == 'PRANK':
  y = random.randint(1, 3)
  if y == 1:
    print('Replace their Oreo frosting with toothpaste.')
  elif y == 2:
    print('Blast into their room with an air horn.')
  elif y == 3:
    print('Blast the FBI meme on a loud speaker on max volume')

Output

Do you want a meme or a prank idea? prank
Blast the FBI meme on a loud speaker on max volume
GOVIND DIXIT
  • 1,748
  • 10
  • 27
0

Guess random.choice more suitable here ? =)

import random

LOL = input("Do you want a meme or a prank idea? ")

prank_or_meme = {
    "meme": [
        "Yee",
        "Yeet!",
        "I got the horses in the back",
        "AND HIS NAME IS JOHN CENA!!!!",
        "IT'S OVER 9000!",
    ],
    "prank": [
        "Replace their Oreo frosting with toothpaste.",
        "Blast into their room with an air horn.",
        "Blast the FBI meme on a loud speaker on max volume",
    ],
}

default = ["Philosoraptor: I don't know, may be it\'s a joke?"]

values = prank_or_meme.get(LOL.lower(), default)
print(random.choice(values))
Oleg Butuzov
  • 4,795
  • 2
  • 24
  • 33
0

First, you arent using or right, you need to do like this:

if LOL == 'Meme' or LOL == 'meme' or LOL == "MEME":

You should use a method named lower or upper instead, like this:

if LOL.lower() == 'meme':

Or this:

if LOL.upper() == 'MEME':

Second, your indentantion not make sense, I will GUESS that you mean:

import random
LOL = raw_input('Do you want a meme or a prank idea? ')
if LOL == 'meme' or 'Meme' or 'MEME':
    x = random.randint(1, 5)
    if x == 1:
        print('Yee')
    elif x == 2:
        print('Yeet!')
    elif x == 3:
        print('I got the horses in the back')
    elif x == 4:
        print('AND HIS NAME IS JOHN CENA!!!!')
    elif x == 5:
        print('IT\'S OVER 9000!')
elif LOL == 'prank' or 'Prank' or 'PRANK':
    y = random.randint(1, 3)
    if y == 1:
        print('Replace their Oreo frosting with toothpaste.')
    elif y == 2:
        print('Blast into their room with an air horn.')
    elif y == 3:
        print('Blast the FBI meme on a loud speaker on max volume')

Why your doesnt work? Cause if receives a boolean value and text string are read like a true value, so when you do:

if 'Im a string':
    print('I will be printed')

The text is printed. Try use my above suggestions. @John Coleman and @jonrsharpe were right.