1

I tried looking at this but to no avail, heres the code I made from the link.

game = 1
while game == 1:
    print('WORLD EVALUATOR 2000')
    word = input("Insert some text...").lower()

    words = word.split(" ")
    lastWord = words[-1]



    if word[0].lower() in 'aeiou':
        print("The string begins with a vowel")
    elif word[0].lower() in '1234567890':
        print ("The string begins with a number")
    elif word[0].lower() in 'bcdfghjklmnpqrstvwxyz':
        print ("The string begins with a consonant")
    elif word[0].lower() in '!@#$%^&*()_+{}|:"<>?':
        print ("The string begins with a symbol or a space.")
    elif word[0].lower() in ' ':
        print ("The string begins with a space.")

    else:
        print("The string does not begin with a vowel,number, consonant, space, or a symbol")

    if word[1].lower() in 'aeiou':
        print("The string's second letter is a vowel")
    elif word[1].lower() in '1234567890':
        print ("The string's second letter is a number")
    elif word[1].lower() in 'bcdfghjklmnpqrstvwxyz':
        print ("The string's second letter is a consonant")
    elif word[1].lower() in '!@#$%^&*()_+{}|:"<>?':
        print ("The string's second letter is a symbol or a space.")
    elif word[1].lower() in ' ':
        print ("The string's second letter is a space.")
    else:
        print("The string's second letter is not a vowel,number, consonant, space, or a symbol")

    if lastWord[-1].lower() in 'aeiou':
        print("The string's last letter is a vowel")
    elif lastWord[-1].lower() in '1234567890':
        print("The string's last letter is a number")
    elif lastWord[-1].lower() in 'bcdfghjklmnpqrstvwxyz':
        print("The string's last letter is a consonant")
    elif lastWord[-1].lower() in '!@#$%^&*()_+{}|:"<>?':
        print("The string's last letter is a symbol or a space.")
    elif lastWord[-1].lower() in ' ':
        print("The string's last letter is a space.")
    else:
        print("The string's last letter is not a vowel,number, consonant, or a symbol")
    print("The string is " + str(len(words)) +  ' letters/numbers/symbols long.')

Near the end is where I used len but it isn't working, could I have some help?

If anyone asks, the while loop isn't properly indented because of the formatting in stackoverflow hating me. In reality the loop works fine expect for the len part.

Community
  • 1
  • 1
  • I get an output that just says it's "1" –  Oct 27 '16 at 19:24
  • WORLD EVALUATOR 2000 Insert some text...Absosc The string begins with a vowel The string's second letter is a consonant The string's last letter is a consonant The string is 1 letters/numbers/symbols long. –  Oct 27 '16 at 19:25
  • 4
    You are counting the number of words not letters – Jean-François Fabre Oct 27 '16 at 19:28
  • 3
    `print("The string is " + str(len(words)) + ' letters/numbers/symbols long.')` should be `print("The string is " + str(len(word)) + ' letters/numbers/symbols long.')` notice the s is gone in word? – MooingRawr Oct 27 '16 at 19:29
  • Ah, Thank you. I didn't catch the fact that the s was there. –  Oct 27 '16 at 19:30

1 Answers1

0

The len function will serve you perfectly well; len(word) will give you the number of characters of your string. The size in bytes which would be needed when saved to a file depends on the encoding.

By the way - to avoid confusion:

  • Don't name a variable word which you expect to contain several words. I'd suggest something like text.
  • Don't use the names of built-in functions for variables (str). It helps to use an editor which features syntax highlighting for Python.
Tobias
  • 2,481
  • 3
  • 26
  • 38