Total newbie!

This is the place for queries that don't fit in any of the other categories.

Total newbie!

Postby DevXux8 » Sat Feb 01, 2014 10:00 am

I am total newbie to coding, i have no real understanding of terminology that is used, but I am trying to understand and tell my problem clearly.

I am trying to code a text chat engine that give you certain possibilities such A, B, C, and those are linked to texts that has been showed on the screen beforely. How can I code such a script?, that when the user pushes A, it will automatically choose the before handed text that I have writen. I am not now at my own computer but I will post the code soon as I get my own laptop soon. Please help.
Code: Select all
age = raw_input(("How old are you? "))

print "So you are " + age

print "I am still a baby. I just got created by my programmer."

print "Where do you want to go?"
print "1)To bathroom?"
print "2)to tv room?"
print "3)to outside?"
print "type your number!"

vastaus = int(raw_input(''))

while True:
    if vastaus < 1 :
        print "nice"

        break
   

I need to know how to make "If user chooce A or 1, then will happend X or 2, if user chooses B or 3 then will happend Y or 4 and so on" How can I create that?
please help.

yours.
Ali
Last edited by Yoriz on Sat Feb 01, 2014 10:14 am, edited 3 times in total.
Reason: Locked OP, Merged posts, Moved to General coding
DevXux8
 
Posts: 15
Joined: Sat Feb 01, 2014 9:53 am

Re: Total newbie!

Postby DevXux8 » Sat Feb 01, 2014 11:40 am

Ok. I managed to solve that problem.
DevXux8
 
Posts: 15
Joined: Sat Feb 01, 2014 9:53 am

Re: Total newbie!

Postby stranac » Sat Feb 01, 2014 12:44 pm

You should post your solution, for others who may have the same problem.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1096
Joined: Thu Feb 07, 2013 3:42 pm

Re: Total newbie!

Postby DevXux8 » Sat Feb 01, 2014 2:32 pm

stranac wrote:You should post your solution, for others who may have the same problem.


I made it two ways. The first one goes like this;
Code: Select all
x=raw_input("Enter name: ")
xx="?"
xxx="!"
a = ('Thats wonderful')
b = ("Sorry to heart that")
c = ("Me too. I feel normal")
print "Hey " + x + xxx
print "How are you " + x[code][/code] + xx
print ("(a)I am fine")
print("(b)I feel awful")
print("(c)I feel normal")

xxxx=raw_input("Choose a letter ")



if xxxx == "a" : print a
if xxxx == "b" : print b
if xxxx == "c" : print c


And the second one goes like this:
Code: Select all

print "What are you going to do today?"
print "C)Going to outside"
print "B)Programming"
print "A)watch porn"


xxxx1=raw_input("Choose a letter: ")

if xxxx1 == 'a' : print "Good job, Louna is going to love it!"
if xxxx1 == 'b' : print "Thats nice, i always dreamed to become and AI"
if xxxx1 == 'c' : print "Walking outside is refressing. You should do it"


press = raw_input("press any key")



Now I am trying to make it in a loop, so that if alphabet is wrong it will go back to the original question. Anyone can help with that? This is what i got now;

Code: Select all
x=raw_input("Enter name: ")

press = raw_input("press any key")


question1 = "How are you " + x
print question1

print ("(a)I am fine")
print("(b)I feel awful")
print("(c)I feel normal")

while True:
    question1 = int(input(question1))
    if question1 == 'a' :
        print ("Good job")
    if question1 == 'b' : print ("Nice job")
    if question1 == 'c' : print "Nice work"

    break

 


But it gives me airmessage like this:

Traceback (most recent call last):
File "C:/Users/a/Desktop/python/exampe.py", line 16, in <module>
question1 = int(input(question1))
File "<string>", line 1, in <module>
NameError: name 'a' is not defined
DevXux8
 
Posts: 15
Joined: Sat Feb 01, 2014 9:53 am

Re: Total newbie!

Postby DevXux8 » Sat Feb 01, 2014 2:49 pm

How can I save .py file to .exe file?
DevXux8
 
Posts: 15
Joined: Sat Feb 01, 2014 9:53 am

Re: Total newbie!

Postby Mekire » Sat Feb 01, 2014 2:52 pm

Never use input with python 2. Only raw_input.

Also you probably want to look into dictionaries:
Code: Select all
my_choices = {"A" : "choice 1",
              "B" : "choice 2",
              "C" : "choice 3"}

choice = None
while choice not in my_choices:
    if choice is not None:
        print("Please select from available options")
    choice = raw_input("Please choose (A,B,C): ").upper()

print("You chose {}.".format(my_choices[choice]))

-Mek

DevXux8 wrote:How can I save .py file to .exe file?
This is an unrelated topic. You also will not find it a trivial process as you are just starting out. Please do a little research first and then if necessary create a new thread asking your question.
User avatar
Mekire
 
Posts: 986
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Total newbie!

Postby DevXux8 » Sat Feb 01, 2014 4:49 pm

'ok, thanks. I will post later what I have came up with. B)
DevXux8
 
Posts: 15
Joined: Sat Feb 01, 2014 9:53 am

Re: Total newbie!

Postby Robinzon Kruso » Sat Feb 01, 2014 9:38 pm

DevXux8 wrote:How can I save .py file to .exe file?


You need to install py2exe which turns Python programs into executable version that you can run as standalone even Python interpreter is not installed on the Windows machine.

For example you have a code saved with name HalloWorld.py:

string=¨Hallo World¨
print string


In order to use py2exe you need to create more one code for example name it exemake.py to tell py2exe what you want to do:

from distutils.core import setup
import py2exe
setup(console=[´HelloWorld.py´])


if you already installed py2exe than run:

python exemake.py py2exe

if evryting went good you will see two new folders /build and /dist

go to /dist

and there is your exe file HelloWorld.exe
Robinzon Kruso
 
Posts: 3
Joined: Fri Jan 10, 2014 2:16 pm

Re: Total newbie!

Postby DevXux8 » Sun Feb 02, 2014 7:00 am

I am still working my text adventure project. Now that I have learned how to make a loop, and have conditional functions, i am wondering how can i save data to libraries when the program is used. I am not looking ready made script, but help is needed? Heres what I got now. :)

Code: Select all
raw_input("You have found a genie, choose random alphabet and get a something .<press button>")





my_choices666= {"A" : " the big sword", #library
              "B" : "huge diaria",
              "C" : "...The geenie had died",
              "H" : "good job",
               "G" : "Nice work",
               "F" : "Awesomeness" }

choice = None
while choice not in my_choices666:
    if choice is not None:
        print("Please select from available options")
    choice = raw_input("Please choose (A,B,C,H,G,F): ").upper()

print("You shall have {}.".format(my_choices666[choice]))
 


Bacily i am wondering how can i save the raw input "choice" to dictionary.. for example that it was A.
Last edited by DevXux8 on Sun Feb 02, 2014 7:12 am, edited 2 times in total.
DevXux8
 
Posts: 15
Joined: Sat Feb 01, 2014 9:53 am

Re: Total newbie!

Postby DevXux8 » Sun Feb 02, 2014 7:01 am

Robinzon Kruso Thanks bro.
DevXux8
 
Posts: 15
Joined: Sat Feb 01, 2014 9:53 am

Re: Total newbie!

Postby Mekire » Sun Feb 02, 2014 7:15 am

DevXux8 wrote:[I] am wondering how can i save data to libraries when the program is used. I am not looking ready made script, but help is needed?
[Basically I] am wondering how can i save the raw input "choice" to dictionary.. for example that it was A.

I'm not honestly sure what you are trying to do.

-Mek
User avatar
Mekire
 
Posts: 986
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Total newbie!

Postby DevXux8 » Sun Feb 02, 2014 8:19 am

Ok. I will post some code after i have got little bit futher....
DevXux8
 
Posts: 15
Joined: Sat Feb 01, 2014 9:53 am

Re: Total newbie!

Postby DevXux8 » Sun Feb 02, 2014 12:08 pm

Why this script does not work?


Code: Select all
aseet = { "tikari" : "tikari"}

valinta = None
while valinta not in aseet:
 if valinta is not None:
  print("Sinulla on tikari")
valinta = raw_input("Valitse tikari").upper()
print("sait tikarin {}.".format(aseet[valinta]))
   
DevXux8
 
Posts: 15
Joined: Sat Feb 01, 2014 9:53 am

Re: Total newbie!

Postby stranac » Sun Feb 02, 2014 12:36 pm

It should work.
But it will enter an infinite loop that prints something if None is not None.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1096
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 1 guest