-1

When trying print something off of a random letter it is only printing the first if statement in each of my functions. Does anyone know how to make it look through each if statement instead of choosing the first one? THX

import string
import random 

rlet1 = random.choice(string.ascii_letters)
rlet2 = random.choice(string.ascii_letters)
rlet3 = random.choice(string.ascii_letters)

def rmor1():
    if rlet1 == ("a") or ("A"):
        print("1")
    elif rlet1 == ("b") or ("B"):
        print("2")
    else:
        print("3")
def rmor2():
    if rlet2 == ("a") or ("A"):
        print("1")
    elif rlet2 == ("b") or ("B"):
        print("2")
    else:
        print("3")
def rmor3():
    if rlet3 == ("a") or ("A"):
        print("1")
    elif rlet3 == ("b") or ("B"):
        print("2")
    else:
        print("3")

rmor1()
rmor2()
rmor3()
Matiiss
  • 5,970
  • 2
  • 12
  • 29
tater tot
  • 1
  • 1
  • 2
    `if rlet1 == "a" or rlet1 == "A":` – Julien Jul 21 '21 at 00:25
  • 1
    it would probably be tho easier if you used `.lower()` method like this: `if rlet1.lower() == 'a':` or even here already: `rlet1 = random.choice(string.ascii_letters).lower()`, that would basically mean that You need to do less checks, however an even better method in my opinion would be to have a dictionary sth like this: `dct = {'a': 1, 'b': 2}` and so on and then You could simply do sth like `print(dct[rlet1.lower()])` – Matiiss Jul 21 '21 at 00:29

1 Answers1

0

You were missing the variable and the comparison operator in the second conditional.

import random
import string

rlet1 = random.choice(string.ascii_letters)
rlet2 = random.choice(string.ascii_letters)
rlet3 = random.choice(string.ascii_letters)

def rmor1():
    if rlet1 == ("a") or rlet1 == ("A"):
        print("1")
    elif rlet1 == ("b") or rlet1 == ("B"):
        print("2")
    else:
        print("3")
def rmor2():
    if rlet2 == ("a") or rlet1 == ("A"):
        print("1")
    elif rlet2 == ("b") or  rlet1 == ("B"):
        print("2")
    else:
        print("3")
def rmor3():
    if rlet3 == ("a") or rlet1 == ("A"):
        print("1")
    elif rlet3 == ("b") or  rlet1 ==("B"):
        print("2")
    else:
        print("3")

rmor1()
rmor2()
rmor3()
Robin Sage
  • 969
  • 1
  • 8
  • 24