0

So I have made a letters game, where the user chooses either a vowel or a consonant, and a random letter from the list of vowels or consonants is selected. Unfortunately, the program is not correctly referring to its array and is producing random letters. How do I fix this?

    intro = raw_input("Welcome to the Letters Game. Press Enter to begin.")
    biglist = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z']
    smalllist = ['A', 'E', 'I', 'O', 'U']
    print "Ok! Let's get started!"
    print ""
    print "Ok, so you get a selection of 9 letters - either vowels or consonants."
    print ""
    first = raw_input("Vowel or consonant? (V or C) ")
    if first == "V" or "v":
        n1 = random.choice(biglist)
        print ""
        print "First letter:", n1
    else:
        n1 = random.choice(biglist)
        print ""
        print "First letter:", n1
    print ""
    second = raw_input("Vowel or consonant? (V or C) ")
    if second == "V" or "v":
        n2 = random.choice(smalllist)
        print ""
        print "Second letter:", n2
    else:
        n2 = random.choice(biglist)
        print ""
        print "Second letter:", n2
    print ""
    third = raw_input("Vowel or consonant? (V or C) ")
    if third == "V" or "v":
        n3 = random.choice(smalllist)
        print ""
        print "Third letter:", n3
    elif third == "C" or "c":
        n3 = random.choice(biglist)
        print ""
        print "Third letter:", n3
    else:
        print "Why you do this"
    print ""
    fourth = raw_input("Vowel or consonant? (V or C) ")
    if fourth == "V" or "v":
        n4 = random.choice(smalllist)
        print ""
        print "Fourth letter:", n4
    elif fourth == "C" or "c":
        n4 = random.choice(biglist)
        print ""
        print "Fourth letter:", n4
    else:
        print "Why you do this"
    print ""
    fifth = raw_input("Vowel or consonant? (V or C) ")
    if fifth == "V" or "v":
        n5 = random.choice(smalllist)
        print ""
        print "Fifth letter:", n5
    elif fifth == "C" or "c":
        n5 = random.choice(biglist)
        print ""
        print "Fifth letter:", n5
    else:
        print "Why you do this"
    print ""
    sixth = raw_input("Vowel or consonant? (V or C) ")
    if sixth == "V" or "v":
        n6 = random.choice(smalllist)
        print ""
        print "Sixth letter:", n6
    elif sixth == "C" or "c":
        n6 = random.choice(biglist)
        print ""
        print "Sixth letter:", n6
    else:
        print "Why you do this"
    print ""
    seventh = raw_input("Vowel or consonant? (V or C) ")
    if seventh == "V" or "v":
        n7 = random.choice(smalllist)
        print ""
        print "Seventh letter:", n7
    elif seventh == "C" or "c":
        n7 = random.choice(biglist)
        print ""
        print "Seventh letter:", n7
    else:
        print "Why you do this"
    print ""
    eighth = raw_input("Vowel or consonant? (V or C) ")
    if eighth == "V" or "v":
        n8 = random.choice(smalllist)
        print ""
        print "Eighth letter:", n8
    elif eighth == "C" or "c":
        n8 = random.choice(biglist)
        print ""
        print "Eighth letter:", n8
    else:
        print "Why you do this"
    print ""
    ninth = raw_input("Vowel or consonant? (V or C) ")
    if ninth == "V" or "v":
        n9 = random.choice(smalllist)
        print ""
        print "Ninth letter:", n9
    elif ninth == "C" or "c":
        n9 = random.choice(biglist)
        print ""
        print "Ninth letter:", n9
    else:
        print "Why you do this"
Ahsanul Haque
  • 10,676
  • 4
  • 41
  • 57
Cooper
  • 45
  • 1
  • 6
  • 1
    What exactly do you mean "producing random letters"? Are you sure it's not just that the first letter is always a consonant? (Also, once you figure this out, let me suggest that you learn about loops next!) – David Z Dec 02 '15 at 08:17
  • n1 is chosen from biglist in both branches, not from smalllist or biglist. – ventik Dec 02 '15 at 08:19
  • Not in the topic but let me suggest you to take a look over this https://wiki.python.org/moin/ForLoop – Netwave Dec 02 '15 at 08:19
  • Why do I need to implement looping for this code? @GaaraofDesert I changed it to smalllist, and although n1 works now, n2 onwards still does not. – Cooper Dec 02 '15 at 08:25
  • Also, I have worked out it does not produce random letters, only vowels. – Cooper Dec 02 '15 at 08:28
  • You should check conditions like that "if fourth == "V" or first == "v":". Because "if first == "V" or "v"" always will be true. – ventik Dec 02 '15 at 08:29
  • Ok so I worked out the problem but I'm not really sure why it was a problem in the first place... when I removed the 'or' statement from the code it worked all of a sudden... can someone please explain why this is and add another answer to my question? – Cooper Dec 02 '15 at 09:36
  • 1
    @Cooper Because "==" requires two operands. For example, a == b. Expression like a == b or c means that python at first calculates a== b and then calculates the result of "a == b" and c. In your case c is non empty string and in logical representation it will always be a true ( http://www.thomas-cokelaer.info/tutorials/python/boolean.html ). That's why you need to compare separatly. Or you can use in operator. Like that "first in ['V', 'v']" – ventik Dec 02 '15 at 11:10

0 Answers0