Re: [Tutor] Here is code, no link for my previous question
On 07/01/13 02:07, Jack Little wrote: Here is the code, my error is below the code in itallics That does not look like a normal Python error report. How are you running this? If you are using an IDE it may be giving non standard messages. It is usually better to run your code from a command line and then send us the full error traceback. It contains a lot of useful information. Although in this case the error is sufficiently explicit that we can pinpoint the error without it. global ammo1 global ammo2 global ammo3 global health global tech_parts global exp global radio_parts These do absolutely nothing, get rid of them. def simpstart(): global ammo global health global tech_parts global radio_parts print "You awake in a haze. A crate,a door and a radio." g1 = raw_input("Which do you choose ") Remember that indentation is significant in Python. By moving the indentation of print out to the margin you have ended your simpstart() function. As a result simpstart() does absolutely nothing. if g1 == "CRATE" or g1 == "Crate" or g1 == "crate": The usual way to do this is use the lower() method of strings: if g1.lower() == 'crate': print "There is a pack of ammo,some food and an odd microchip" ammo1=ammo1 + 6 > health=health + 10 > tech_parts=tech_parts + 1 You can use the += shortcut to save typing ammo1 += 6 health += 10 tech_parts += 1 elif g2 == "NORTH" or g2 == "North" or g2 == "north": def path_1pt1(): print "This is where it all started. Freedom Tower. A biotech firm called Aesthos Biotechnology. Based here." You are now trying to define a new function inside the elif block. That's legal Python and you can do it if you really want to, but its very unusual style. Normally functions are defined at outer level and called when needed. def path_1pt2(): print "There is a barbed wire topped fence, about 7 feet high. There is a building." print "The weather is picking up, and the wind is getting fast and violent." p5 = raw_input("Stay outside and risk it or check the inside of the building ") if p5 == "Stay" or p5 == "STAY" or p5 == "stay": print "The wind and snow picked up. You got frostbite" return path_1pt1() elif p5 == "CHECK" or p5 == "Check" or p5 == "check": print "There is a group of survivors huddled in a corner" print """Survivor 1: Who are you? Me: Does that matter? Survivor 2: You aren't of 'em Protectors are ya? Me: The what? Survivor 1: They go around killin' people who don't comply with their rules and live in New Quebec" Me:Huh""" exp=exp+200 health=health+50 ammo1=ammo1+29 p6 = raw_input("Do you wish to take a quest or continue the story? ") p6 is defined inside the path_1pt2 function but not returned. if p6 == "QUEST" or p6 == "Quest" or p6 == "quest": This line is not part of the function but tests p6. That won;t work. I suspect its an indentation error. indentation is very important in Python. quest1() Since the quest() function is not defined in your code I assume you are importing it from some other module? elif p6 == "CONTINUE STORY" or p6 == "Continue story" or p6 == p9 = raw_input("Go east or west ") if p9 == "EAST" or p9 == "east" or p9 == "East": def GasStation(): if p10.lower== "approach kindly": print """Me: Hey Guys! ammo1=ammo1-6 And this is the end of your GasStation() function because the next line is not indented... else: print"They murdered you!" return GasStation() ammo1=ammo1-6 And the above is probably where your error occurs since return is indeed outside of a function. Incidentally if it were in a function the ammo line would never get executed since it is after the return, so it is pointless. else: return path1_pt2() "A snowstorm swept through, killing you." Same here, the return is outside a function. And the following string is meaningless Here is the error: There's an error in your program: ***'return' outside function(g.py,line 179) As I say, please run the program in an environment that prints proper python error messages and send the full error text in future. You need to go away and read about indentation, function definitions and namespaces. They are the biggest problems in your code at present. Also please use bigger indentation size, a single character makes it really hard to read and spot which indent lines up with what. Also these very long control structures likewise make it hard to look up and see what aligns with what above. (If with else/elif etc) That all makes your code much harder to maintain and debug. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tut
Re: [Tutor] Here is code, no link for my previous question
On 01/06/2013 09:07 PM, Jack Little wrote: > Here is the code, my error is below the code in itallics This is a text mailing list, italics aren't generally visible. If you want to highlight a line, add a useful comment to it. But the problem here is your scoping. All those globals make no sense, since the keyword only has an effect inside a function. Then you define a function simpstart(), but it's only four lines long, consisting of four more global statements. in other words, the function does nothing. Then after some more top-level code, you define another function path_lpt1(), but the definition is inside a conditional. This is legal, but not likely what you intended to do. Then you define another function path_lpt2(), but end it suddenly after the line p6=raw_input(I'd expect the next line to get an error, referencing an unknown p6. You have a line health=100 immediately after a return statement, so it'll never execute. And as Oscar points out, you have a return at top-level code, which is to say, not inside any function. Not sure where you got this code, but there's probably lots more wrong; I only really looked at the indentation. I think you're confusing defining a function with calling it. And i suspect you typed the whole thing from a book or something, and just got the whole indentation wrong. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Here is code, no link for my previous question
And a second reply: On 07/01/13 13:07, Jack Little wrote: def simpstart(): global ammo global health global tech_parts global radio_parts This function does nothing. It declares four globals, and then ends. All the subsequent lines of code are not indented, and so are not part of the function. I am pretty sure that last time you asked about a problem with this code, I told you the same thing. Why are you asking questions if you don't listen to the answer? See my email on the tutor list on 15/12/12. If you don't understand our answers, please ask for further clarification rather than just ignore them. Ignoring answers will be a good way to have your questions ignored too. else: return path1_pt2() "A snowstorm swept through, killing you." Here is the error: There's an error in your program: ***'return' outside function(g.py,line 179) Is that error message not clear enough? You have an "return" statement outside of a function. This is not allowed, because there is nothing to return from, or return to. When asking questions, please try to avoid sending your entire program. Please try to narrow the problem down to the smallest amount of code that fails. We're happy to *help*, but we're not here to do your work for you. In this case, the simplest example that gives you this error may be something like this: def test(): print "inside function test" # indented, inside function return 1 # not indented, outside function -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Here is code, no link for my previous question
On 07/01/13 13:07, Jack Little wrote: Here is the code, my error is below the code in itallics What italics? I see no italics. Please don't rely on so-called "rich text" email (italics, fancy fonts, different text sizes, etc), since it uses HTML code in your email and many people turn off such HTML code, or are literally unable to see it even if they wanted to. - HTML code in email is one of the top 3 signs of spam. Many people send "rich text" email straight to the trash as a way of eliminating spam. - HTML code in email is a privacy and security risk. For example, that means that the sender can track whether or not you have read the email using "web bugs" whether or not you consent to being tracked. There are viruses, spyware and other malware that can be transmitted through HTML code in email. - HTML code forces your choice in font, font size, colours, etc. on the reader. Some people prefer to read emails using their own choice of font rather than yours, and consider it rude for others to try to force a different font. - Even if they don't mind the use of "rich text" in principle, in practice once they have received enough emails with pink and yellow text on a purple background with blinking stars and dancing fairies in the background, in pure self-defence they may disable HTML in emails, or delete the emails unread. - Use of colour discriminates against the approximately 10% of the male population who are colour-blind. - Use of italics may discriminate against those who are blind and using screen readers to "read" their email. I once was on a maths mailing list for about three years until I discovered that the most prolific and helpful person there was as blind as a bat. - Programming is a *text-based* activity. Code depends on WHAT you write, not its colour, or the font you use, or whether there are smiley faces in the background winking at you. So especially in programming circles, many people find HTML code in emails to be a distraction and an annoyance. Even if you think that people who dislike HTML emails are wrong, or silly, or being precious, or completely nuts, nevertheless you should indulge us. You are asking for free advice. It does not pay for you to offend or annoy those you are asking for help. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Here is code, no link for my previous question
On 7 January 2013 02:07, Jack Little wrote: > Here is the code, my error is below the code in itallics No explanation? > > #This is not free source > #Don't cheat by looking at this > #If you do you ruin the game I was a little concerned when I read this part. I guess it's okay for me to read on... > #A Towel Production > # APOC > #--- > global ammo1 > global ammo2 > global ammo3 > global health > global tech_parts > global exp > global radio_parts > ammo1=10 > ammo2=0 > ammo3=0 > health=100 > tech_parts=0 > exp=0 > radio_parts=0 > def simpstart(): > global ammo > global health > global tech_parts > global radio_parts > print "You awake in a haze. A crate,a door and a radio." > g1 = raw_input("Which do you choose ") > if g1 == "CRATE" or g1 == "Crate" or g1 == "crate": > print "There is a pack of ammo,some food and an odd microchip" > ammo1=ammo1 + 6 > health=health + 10 > tech_parts=tech_parts + 1 > elif g1 =="DOOR" or g1 == "Door" or g1 == "door": > print "You are outside" > elif g1 == "RADIO" or g1 == "Radio" or g1 == "radio": > print "It's only a few parts" > radio_parts=radio_parts+3 > g2 = raw_input("So this is NYC.Ten years after.There are a few streets.Go > west or north ") > if g2 == "WEST" or g2 == "West" or g2 == "west": > path2() > elif g2 == "NORTH" or g2 == "North" or g2 == "north": > > def path_1pt1(): > print "This is where it all started. Freedom Tower. A biotech firm > called Aesthos Biotechnology. Based here." > print "I worked there." > p1 = raw_input("Go in or stay out ") > if p1 == "GO IN" or p1 == "Go in" or p1 == "go in": > print health > print tech_parts > print ammo1 > print "This looks familiar" > print """Flashback 1 > Boss: Hey! You go get sample SV57 from the freezer. > Me: Will do sir > Lab technician: thanks > Me: No problem""" > print "Not much in here" > elif p1 =="STAY OUT" or p1 == "Stay out" or p1 == "stay out": > print "It seems a lot of people died here" > print """Flashback 1.2 > Test subject: AHHGHWhat the what! > Lab technician: God! What is happening? > Me: What sample was that? > Lab technician: SV57 > Me: RUN LIKE HECK! > The lab tech was infected > Me: All my fault...All my fault""" > print """Man: Hello. > Me: Who are you. > Man:That is...unnecessary at this time. > Me: Then why are you here? > Man: To help > Man: I know where your family is. > Me: Where?! > Man: Ontario, Canada. That is 282 miles.""" > print " Man: This a long journey, but I believe you can accomplish it." > print > print > print "Ontario is north. Got to get there." > p2 = raw_input("There is a pack of crawlers up ahead. Attack or sneak > ") > if p2 == "ATTACK" or p2 == "Attack" or p2 == "attack": > print "You attacked the crawlers at the loss of 6 ammo and 19 > health, but gained 55 exp" > ammo1=ammo1-6 > health=health-19 > exp=exp+55 > elif p2 == "SNEAK" or p2 == "Sneak" or p2 == "sneak": > print "You snuck past the crawlers at the gain of 45 exp" > exp=exp+45 > p3 = raw_input("Gangster: You! What you got?! Attack or run away ") > if p3 == "ATTACK" or p3 == "Attack" or p3 == "attack": > print "Several of his comrades swarm you. You died." > return path_1pt1() > health=100 > elif p3 == "Run away" or p3 == "RUN AWAY" or p3 == "run away": > print "You got away, but you know you made one more enemy today" > p4 = raw_input("A car drives up. Do you carjack it or keep walking ") > if p4 == "CARJACK" or p4 == "Carjack" or p4 == "carjack": > path_1pt3() > elif p4 == "Walk" or p4 == "WALK" or p4 == "walk": > print "That was a golden opportunity" > > def path_1pt2(): > print "There is a barbed wire topped fence, about 7 feet high. There is > a building." > print "The weather is picking up, and the wind is getting fast and > violent." > p5 = raw_input("Stay outside and risk it or check the inside of the > building ") > if p5 == "Stay" or p5 == "STAY" or p5 == "stay": > print "The wind and snow picked up. You got frostbite" > return path_1pt1() > elif p5 == "CHECK" or p5 == "Check" or p5 == "check": > print "There is a group of survivors huddled in a corner" > print """Survivor 1: Who are you? > Me: Does that matter? > Survivor 2: You aren't of 'em Protectors are ya? > Me: The what? > Survivor 1: They go around killin' people who don't comply > with their rules and live in
[Tutor] Here is code, no link for my previous question
Here is the code, my error is below the code in itallics #This is not free source #Don't cheat by looking at this #If you do you ruin the game #A Towel Production # APOC #--- global ammo1 global ammo2 global ammo3 global health global tech_parts global exp global radio_parts ammo1=10 ammo2=0 ammo3=0 health=100 tech_parts=0 exp=0 radio_parts=0 def simpstart(): global ammo global health global tech_parts global radio_parts print "You awake in a haze. A crate,a door and a radio." g1 = raw_input("Which do you choose ") if g1 == "CRATE" or g1 == "Crate" or g1 == "crate": print "There is a pack of ammo,some food and an odd microchip" ammo1=ammo1 + 6 health=health + 10 tech_parts=tech_parts + 1 elif g1 =="DOOR" or g1 == "Door" or g1 == "door": print "You are outside" elif g1 == "RADIO" or g1 == "Radio" or g1 == "radio": print "It's only a few parts" radio_parts=radio_parts+3 g2 = raw_input("So this is NYC.Ten years after.There are a few streets.Go west or north ") if g2 == "WEST" or g2 == "West" or g2 == "west": path2() elif g2 == "NORTH" or g2 == "North" or g2 == "north": def path_1pt1(): print "This is where it all started. Freedom Tower. A biotech firm called Aesthos Biotechnology. Based here." print "I worked there." p1 = raw_input("Go in or stay out ") if p1 == "GO IN" or p1 == "Go in" or p1 == "go in": print health print tech_parts print ammo1 print "This looks familiar" print """Flashback 1 Boss: Hey! You go get sample SV57 from the freezer. Me: Will do sir Lab technician: thanks Me: No problem""" print "Not much in here" elif p1 =="STAY OUT" or p1 == "Stay out" or p1 == "stay out": print "It seems a lot of people died here" print """Flashback 1.2 Test subject: AHHGHWhat the what! Lab technician: God! What is happening? Me: What sample was that? Lab technician: SV57 Me: RUN LIKE HECK! The lab tech was infected Me: All my fault...All my fault""" print """Man: Hello. Me: Who are you. Man:That is...unnecessary at this time. Me: Then why are you here? Man: To help Man: I know where your family is. Me: Where?! Man: Ontario, Canada. That is 282 miles.""" print " Man: This a long journey, but I believe you can accomplish it." print print print "Ontario is north. Got to get there." p2 = raw_input("There is a pack of crawlers up ahead. Attack or sneak ") if p2 == "ATTACK" or p2 == "Attack" or p2 == "attack": print "You attacked the crawlers at the loss of 6 ammo and 19 health, but gained 55 exp" ammo1=ammo1-6 health=health-19 exp=exp+55 elif p2 == "SNEAK" or p2 == "Sneak" or p2 == "sneak": print "You snuck past the crawlers at the gain of 45 exp" exp=exp+45 p3 = raw_input("Gangster: You! What you got?! Attack or run away ") if p3 == "ATTACK" or p3 == "Attack" or p3 == "attack": print "Several of his comrades swarm you. You died." return path_1pt1() health=100 elif p3 == "Run away" or p3 == "RUN AWAY" or p3 == "run away": print "You got away, but you know you made one more enemy today" p4 = raw_input("A car drives up. Do you carjack it or keep walking ") if p4 == "CARJACK" or p4 == "Carjack" or p4 == "carjack": path_1pt3() elif p4 == "Walk" or p4 == "WALK" or p4 == "walk": print "That was a golden opportunity" def path_1pt2(): print "There is a barbed wire topped fence, about 7 feet high. There is a building." print "The weather is picking up, and the wind is getting fast and violent." p5 = raw_input("Stay outside and risk it or check the inside of the building ") if p5 == "Stay" or p5 == "STAY" or p5 == "stay": print "The wind and snow picked up. You got frostbite" return path_1pt1() elif p5 == "CHECK" or p5 == "Check" or p5 == "check": print "There is a group of survivors huddled in a corner" print """Survivor 1: Who are you? Me: Does that matter? Survivor 2: You aren't of 'em Protectors are ya? Me: The what? Survivor 1: They go around killin' people who don't comply with their rules and live in New Quebec" Me:Huh""" exp=exp+200 health=health+50 ammo1=ammo1+29 p6 = raw_input("Do you wish to take a quest or continue the story? ") if p6 == "QUEST" or p6 == "Quest" or p6 == "quest": quest1() elif p6 == "CONTINUE STORY" or p6 == "Continue story" or p6 == "continue story": print "You declined the quest