Jump to content

making a AI

Go to solution Solved by madknight3,

Ok, then you can add that input line back in, just use raw_input instead of input.

 

You're probably also going to want to add a check to make sure they typed "computer", if not, then exit.

okay guys im pretty new to python i have decide to make a talking AI like siri my first goal is to get it working via text then to make a GUI then some sort of voice then put it on a raspberry PI, this is what i have so far 

import timeprint ("welcome to the AI")comp = input() if comp == "computer":    instr = input("instrustion?")if instr == "play noel gallagher if i had a gun":        print ("playing if i had a gun by noel gallagher")elif instr == "who is your creator":        print ("you james")        else:    print ("sorry i miss heard")    

im trying to nest the second if statement  between the first if and the last else how would i do this? i have tried an indent but i get unexpected indent!

btw this is just a start to get a rough idea on how to do this!

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/245301-making-a-ai/
Share on other sites

Link to post
Share on other sites

The indent works, but the inst line has to match the indent for the following if statement, when I copy/pasted they were slightly off.

if comp == "computer":    instr = input("instrustion?") #3 spaces in front of inst not a full indent (indents are usually a multiple of 4 spaces by default so "tabbing" to indent the other lines doesn't match up)    # extra space in front of the below code from indent    if instr == "play noel gallagher if i had a gun":        print ("playing if i had a gun by noel gallagher")    elif instr == "who is your creator":        print ("you james")else:    print ("sorry i miss heard")
Link to comment
https://linustechtips.com/topic/245301-making-a-ai/#findComment-3367235
Share on other sites

Link to post
Share on other sites

 

The indent works, but the inst line has to match the indent for the following if statement, when I copy/pasted they were slightly off.

if comp == "computer":    instr = input("instrustion?") #3 spaces in front of inst not a full indent (indents are usually a multiple of 4 spaces by default so "tabbing" to indent the other lines doesn't match up)    # extra space in front of the below code from indent    if instr == "play noel gallagher if i had a gun":        print ("playing if i had a gun by noel gallagher")    elif instr == "who is your creator":        print ("you james")else:    print ("sorry i miss heard")

okay thanks that heled alot now i have added a while loop so it loops back to the start to re ask the questions but it doesnt seem to want to go back to the top it just stops at the end of the instructio! 

import timeprint ("welcome to the AI")while 0==0:    comp = input()    instr = input("instrustion?")    if instr == "play noel gallagher if i had a gun":        print ("playing if i had a gun by noel gallagher")    elif instr == "who is your creator":        print ("you james")    elif instr == "what are you doing":        print ("not alot")    else:        print ("sorry i miss heard")    

if you could help with that i would be so happy!

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/245301-making-a-ai/#findComment-3367281
Share on other sites

Link to post
Share on other sites

Fixed with comments:

import timeprint ("welcome to the AI")while True:  # Use True instead of 0==0    #comp = input()  # Why are you asking for input here? I removed it. If you want a new line, just use print    instr = raw_input("instrustion?")  # Use raw_input instead of input (source: http://stackoverflow.com/a/4960216/1765721)    if instr == "play noel gallagher if i had a gun":        print ("playing if i had a gun by noel gallagher")    elif instr == "who is your creator":        print ("you james")    elif instr == "what are you doing":        print ("not alot")    else:        print ("sorry i miss heard")    

Output

welcome to the AIinstrustion?play noel gallagher if i had a gunplaying if i had a gun by noel gallagherinstrustion?hsjshssorry i miss heardinstrustion?kjhskjsorry i miss heardinstrustion?who is your creatoryou jamesinstrustion?what are you doingnot alotinstrustion?
Link to comment
https://linustechtips.com/topic/245301-making-a-ai/#findComment-3367343
Share on other sites

Link to post
Share on other sites

 

Fixed with comments:

import timeprint ("welcome to the AI")while True:  # Use True instead of 0==0    #comp = input()  # Why are you asking for input here? I removed it. If you want a new line, just use print    instr = raw_input("instrustion?")  # Use raw_input instead of input (source: http://stackoverflow.com/a/4960216/1765721)    if instr == "play noel gallagher if i had a gun":        print ("playing if i had a gun by noel gallagher")    elif instr == "who is your creator":        print ("you james")    elif instr == "what are you doing":        print ("not alot")    else:        print ("sorry i miss heard")    

Output

welcome to the AIinstrustion?play noel gallagher if i had a gunplaying if i had a gun by noel gallagherinstrustion?hsjshssorry i miss heardinstrustion?kjhskjsorry i miss heardinstrustion?who is your creatoryou jamesinstrustion?what are you doingnot alotinstrustion?

no i want it so after every instruction you have to type computer again to type another instruction in hers a vid that im basing the whole program on 

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/245301-making-a-ai/#findComment-3367363
Share on other sites

Link to post
Share on other sites

Ok, then you can add that input line back in, just use raw_input instead of input.

 

You're probably also going to want to add a check to make sure they typed "computer", if not, then exit.

yeah python 3.4 you cant use raw_input i dont think, i have added the cpommand back in but still it just stops at playing noel gallagher if i had a gun

import timeprint ("welcome to the AI")while True:     comp = input()    if comp =="computer":        instr = input("instrustion?")    else:        print ("sorry i miss heard")    if instr == "play noel gallagher if i had a gun":        print ("playing if i had a gun by noel gallagher")    elif instr == "who is your creator":        print ("you james")    elif instr == "what are you doing":        print ("not alot")    else:        print ("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 comment
https://linustechtips.com/topic/245301-making-a-ai/#findComment-3367406
Share on other sites

Link to post
Share on other sites

Ah, my mistake. I assumed Python 2.7. You should specify ;)

 

(or maybe I should have noticed from your print statements :P )

do you have ideas then? how i can loop back to the start of the while

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/245301-making-a-ai/#findComment-3367437
Share on other sites

Link to post
Share on other sites

 

yeah python 3.4 you cant use raw_input i dont think, i have added the cpommand back in but still it just stops at playing noel gallagher if i had a gun

It's not stopping, it's waiting for more input from the line

comp = input()

Just enter "computer" again.

1474412270.2748842

Link to comment
https://linustechtips.com/topic/245301-making-a-ai/#findComment-3367444
Share on other sites

Link to post
Share on other sites

It's not stopping, it's waiting for more input from the line

comp = input()

Just enter "computer" again.

oh yeah thanks blonde moment! 

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/245301-making-a-ai/#findComment-3367472
Share on other sites

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

×