Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 14th, 2005, 3:02 PM   #1
lingon
Newbie
 
Join Date: Apr 2005
Posts: 17
Rep Power: 0 lingon is on a distinguished road
Breaking?

Hello again!
Since I'm really new to this I've got to ask again. I'm having trouble with making a program end if a certian word is inserted in the program, but if some thing else is inserted I want it to continue. Now I might just use the method were the program kills it self when there are no more lines(Sane thought me that ) but I've already used it once and I didnt realy get that with the sys.exit thing. I gues that it has something to do with moduels but I dont know what taht is. Take a look at this:

#Ett enkelt program som jag skapat för att lära mig
#hur man programerar två olika alternativa "vägar" i samma program.
kod = raw_input("Skriv kod:")
if kod == "1798":
print "Åtkomst bekräftad"
print "Välkommen"
print "Du är bäst"
print "men är du det?"
abc = raw_input("")
if abc == "ja":
print "så sant, så sant"
if abc == "ja":
break ###This is were I want it to shut down if "ja" is typed but to continue if something else is typed###(This line is not actually in the program)
if abc == "nej":
print "det är du visst det"
print "du måste bara ha lite självförtroende"
if abc == "jepp":
print "vad var det för ett svar?"
print "du måste svara antingen ja eller nej, ditt nöt, det"
print "här programmet är inte så avancerat"
print "ja eller nej?"
ja = raw_input("")
if ja == "ja":
print "så sant, så sant"
if abc == "nepp":
print "vad var det för ett svar?"
print "du måste svara antingen ja eller nej, ditt nöt, det"
print "här programmet är inte så avancerat"
print "ja eller nej?"
ja = raw_input("")
if ja == "nej":
print "så sant, så sant"
else:
print "Åtkomst nekad"
print "Avslutar program"

If anybody wants me to translate it into english I'd be happy to do so.
Thanks/Lingon
lingon is offline   Reply With Quote
Old Apr 14th, 2005, 3:26 PM   #2
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
Try wrapping your code in [code] tags so we can read it. If you use the advanced reply, it's the button that looks like a pound sign.
Moldz is offline   Reply With Quote
Old Apr 15th, 2005, 9:23 AM   #3
lingon
Newbie
 
Join Date: Apr 2005
Posts: 17
Rep Power: 0 lingon is on a distinguished road
kod = raw_input("Skriv kod:")
if kod == "1798":
    print "Åtkomst bekräftad"
    print "Välkommen"
    print "Du är bäst"
    print "men är du det?"
    abc = raw_input("")
    if abc == "ja":
        print "så sant, så sant"
    if abc == "ja":
        break ###This is were I want it to shut down if "ja" is typed but to continue if something else is typed###(This line is not actually in the program)
    if abc == "nej":    
            print "det är du visst det"
            print "du måste bara ha lite självförtroende"
    if abc == "jepp":
        print "vad var det för ett svar?"
        print "du måste svara antingen ja eller nej, ditt nöt, det"
        print "här programmet är inte så avancerat"
        print "ja eller nej?"
    ja = raw_input("")
    if ja == "ja":
        print "så sant, så sant"
    if abc == "nepp":
        print "vad var det för ett svar?"
        print "du måste svara antingen ja eller nej, ditt nöt, det"
        print "här programmet är inte så avancerat"
    print "ja eller nej?"
    ja = raw_input("")
    if ja == "nej":
            print "så sant, så sant"

There we go.
lingon is offline   Reply With Quote
Old Apr 15th, 2005, 11:41 AM   #4
lingon
Newbie
 
Join Date: Apr 2005
Posts: 17
Rep Power: 0 lingon is on a distinguished road
I modified it abit and it looks like this now:
#Ett enkelt program som jag skapat för att lära mig
#hur man programerar två, eller flera, olika alternativa "vägar" i samma program.
kod = raw_input("Skriv kod:")
if kod == "1798":
    print "Åtkomst bekräftad"
    print "Välkommen"
    print "Du är bäst"
    print "Men är du det?"
                                  ##If "ja" is typed here I want it to end after "Avslutar programm"##
    abc = raw_input("")
    if abc == "ja":
            print "så sant, så sant"
            print "Avslutar program"
    if abc == "nej":    
            print "det är du visst det"
            print "du måste bara ha lite självförtroende"
    else: print "vad var det för ett svar?"
    print "Du måste svara entingen ja eller nej."
    print "Det här programmet är inte så avancerat."

    sa = raw_input("så, ja eller nej?")
    if sa == "ja":
            print "så sant, så sant"
    if sa == "nej":    
            print "det är du visst det"
            print "du måste bara ha lite självförtroende"
    else: print "vad var det för ett svar?"
    print "Du måste svara entingen ja eller nej."
    print "Det här programmet är inte så avancerat."
    print "för sista gången:"

    ek = raw_input ("ja eller nej?")
    if ek == "ja":
        print "så sant, så sant"
    else: print "Avslutar program"
else:
    print "Åtkomst nekad"
    print "Avslutar program"

So, what I want it to do is that if the answer "ja" is typed after the question "men är du det?", give me a certain line of text and then kill itself; but it just keeps going and I dont really know what to do about it. The same goes with the answer "nej". However it does give me that certain line of text that I wanted (both with "ja" nad "nej"), but then it just keeps going like before. The only thing that really works is if you type in something unknown after the question because it is THEN that I want it to continue until either "ja" or "nej" is typed. I tried a few things but none of them seemed to work.
I't be nice with som pro help here/lingon =)

Last edited by lingon; Apr 15th, 2005 at 11:43 AM.
lingon is offline   Reply With Quote
Old Apr 15th, 2005, 12:15 PM   #5
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
If you want it to kill itself after ja is typed. After you print the result of 'ja', indent the rest of the program with "else:". If you don't understand, I'll write it out for you.
Sane is offline   Reply With Quote
Old Apr 15th, 2005, 5:43 PM   #6
lingon
Newbie
 
Join Date: Apr 2005
Posts: 17
Rep Power: 0 lingon is on a distinguished road
Yeah, I'd be nice if you could write it for me. Then I would learn it for sure. I'm sorry to bother you with all these stupid newbie questions, but I've only been programming for 3 days so...
/lingon
lingon is offline   Reply With Quote
Old Apr 18th, 2005, 12:07 PM   #7
lingon
Newbie
 
Join Date: Apr 2005
Posts: 17
Rep Power: 0 lingon is on a distinguished road
the problem id that if I indent the rest with "else" then it will, ofcourse, take the answer "nej" as else and I dont want that.
lingon is offline   Reply With Quote
Old Apr 18th, 2005, 12:11 PM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
use elif (short for else if):
elif sa == "nej":
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 18th, 2005, 12:28 PM   #9
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 5 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
if elif else, as Ooble suggested.
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old Apr 20th, 2005, 1:29 PM   #10
lingon
Newbie
 
Join Date: Apr 2005
Posts: 17
Rep Power: 0 lingon is on a distinguished road
aha. Thanks alot guys!
lingon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC