Jump to content

okay so im making an AI at the moment as my first programming project its doing some strange things please help me fix them! the image is a gif you should be able to see it if you click on it 

post-38716-0-10694400-1415451528_thumb.g

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to comment
https://linustechtips.com/topic/246821-python-program-help-doing-strange-stuff/
Share on other sites

Link to post
Share on other sites

You should say what these things are.

its really hard to explain somethimes it wont play at all and just say sorry i miss heard and when i type in play the death of you and me i get sorry i miss heard

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to post
Share on other sites

Just noticed that your attachment is a gif that shows things a little. I'll try to help you out later if no one else does it first.

thanks mate

Check out my current projects: Selling site (Click Here)

If($reply == "for me to see"){

   $action = "Quote me!";

}else{

   $action = "Leave me alone!";

}

Link to post
Share on other sites

I'm not sure why in the gif, "play dream on" wasn't recognized. The last instruction you wrote had a typo so that's why that one didn't work. There's also an error or invalid behaviour if you don't type "computer" in when that's required because it continues on to check the instr variable.

 

Here's a few changes to your code that I would make at this point. Some of this might be new to you but it's good to learn about these concepts. I don't see any weird behaviour with the following code for me.

import osdef main():    start_ai()def start_ai():    while True:        print("welcome to the AI")        comp = input().lower()  # get input and convert that input to all lowercase before assigning it to comp        if comp == "computer":            instr = input("instruction? ")            parse_instruction(instr.lower())  # only parse instruction if "computer" was entered and make the instr lowercase        elif comp == "exit":  # added a way for the user to exit the infinite loop            return        else:            print("sorry i miss heard")def parse_instruction(instr):    if instr == "play if i had a gun":        print("playing if i had a gun by noel gallagher")        play("ifihadagun.mp3")    elif instr == "play dream on":        print("playing noel gallagher dream on")        play("dreamon.mp3")    elif instr == "play everybody's on the run":        print("playing noel gallagher everyboad's on the run")        play("everybodysontherun.mp3")    elif instr == "play the death of you and me":        print("playing noel gallagher the death of you and me")        play("thedeathofyouandme.mp3")    elif instr == "who is your creator":        print("you james")    elif instr == "what are you doing":        print("not alot")    else:        print("sorry i miss heard")def play(filename):    path = "C:/Users/James/ai/music/"    command = "start {0}{1}".format(path, filename)  # string formatting described below    os.system(command)if __name__ == '__main__':    main()

I split the code into functions and used the main function. In case you don't know about the main function yet, if __name__ == '__main__': is explained here and the reason I added def main() along with it is described here.

 

The line command = "start {0}{1}".format(path, filename) uses string formatting. Examples here and here.

 

I also used the .lower() function to convert the string to all lowercase so case doesn't matter. "Play Dream On" is as valid as "PLAY DREAM ON" is as valid as "play dream on" etc

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×