Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python simple console game

I’ve made this console application that just add ‘ing’ to the verbs given, but when I try to remove the letter ‘e’ at the end of the verbs I get this error: " ‘str’ object does not support item assignment "…THANKS!!!

import os

print("---What to do?---"+"\n")

command=""
verbs=[1,2]

while  True:
    command=input("What should I do now? ").lower()
    if command[-1]=="e":
        command[-1]=""
    verbs.append(command)

    if command=="help":
        print("\n"+"Just give me verb!"+"\n")
    elif command=="rest":
        print("\n"+"Fine, bye!")
        break
    elif command=="clear":
        os.system('cls')
        print("---What to do?---"+"\n")
    else:

        if verbs[-1]!=verbs[-2]:
            print("\n"+"Ok I'm "+command+"ing"+"\n")
        else:
            print("\n"+"I'm tired of "+command+"ing"+"\n")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To remove the last letter from the string just use command[:-1].

import os

print("---What to do?---"+"\n")

command=""
verbs=[1,2]

while  True:
    command=input("What should I do now? ").lower()
    if command[-1]=="e":
        command = command[:-1]
        # there is one more way
        # command = list(command)
        # command[-1]=""
        # command = ''.join(command)
    verbs.append(command)

    if command=="help":
        print("\n"+"Just give me verb!"+"\n")
    elif command=="rest":
        print("\n"+"Fine, bye!")
        break
    elif command=="clear":
        os.system('cls')
        print("---What to do?---"+"\n")
    else:

        if verbs[-1]!=verbs[-2]:
            print("\n"+"Ok I'm "+command+"ing"+"\n")
        else:
            print("\n"+"I'm tired of "+command+"ing"+"\n")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading