PDA

View Full Version : Python help?



Gligarman2
2013-08-03, 09:02 AM
I have no idea why this is using invalid syntax. Any gitp coders why know why?

print("Welcome to the world of Lastreach. You are the great hero Edridian Dualscar. You are trapped in the lair of an angry dragon, which sleeps on a pile of gold. You have your cloth ROBES, a SWORD, and a STICK. You can ABSCOND, MOVE, ATTACK, say YES or NO, or USE one item on another")
print("What do you do?")
input()
if input is ("KILL DRAGON") print("Attack LEGS, CHEST or HEAD")
if input is ("TAKE GOLD") print("The dragon kills you for stealing its gold.") quit
if input is not ("TAKE GOLD") or ("KILL DRAGON") or ("USE ROBES on DRAGON") or ("USE ROBES on SWORD") or ("USE STICK on SWORD") or ("Use SWORD on ROBES") or ("ABSCOND") or ("USE SWORD on STICK")
if input is ("USE robes on DRAGON") print(" The dragon declines the offering. It kills you") quit
if input is ("USE ROBES on SWORD") print("You cut your robes. Dumbass. The dragon eats you for being such a moron") quit
if input is ("USE STICK ON SWORD") print("You now have a longer sword While you were working on that, the dragon sneaks up on you. You die.") quit
if input is ("USE SWORD on STICK") print("You cut a stick. Dumbass.") quit
input
if input is not("KILL LEGS") print("The dragon stomps you flat.It pinches you all over.") quit
if input is("KILL LEGS") print("The dragon is crippled.Attack the CHEST or HEAD?")
input()
if input ("KILL HEAD") print("You stab the dragon through the eye.viciously. You can now take gold from the dragon's hoard.")
input()
if input ("TAKE GOLD") print("You now have 100 gold") print("You leave the dragon's lair")
print("You are on a dusty road. A Highwayman appears.)"
input()
if input() = ("KILL highwayman") print("He's dead, would you like to go on?") else print("You get stabbed.")quit
input() if input() = ("MOVE") print"(You go forward") else print("You sit there like a moron. <") quit
if input()= ("MOVE") print ("You go forward") else print("You sat there like a moron for years. You grow a long beard, and eventually die of old age.")quit

Selpharia
2013-08-03, 12:49 PM
I'm not all that familiar with Python, but one of your input() statements lacks a (), right after "USE SWORD on STICK"

Bryn
2013-08-03, 01:07 PM
Only ever slightly dabbled in Python, but which version are you using? If you're not in Python v3+ then print is a statement, not a function.

I'm not sure if this is a thing in Python, but you don't seem to be storing result of input in any variable. Should it not be something like input = input() (although I wouldn't want to call the variable input to avoid confusion with the function anyway)? However, if Python automatically stores the result in a variable input, that doesn't matter.

Also, you have some inconsistency in how you're using if statements. Assuming most of them use the correct syntax, should e.g. if input ("KILL HEAD") not be if input is ("KILL HEAD")? Further, as a style thing, I'm pretty sure you don't need to enclose all your strings in brackets!

For a game like this, I'm not sure Python is the best language - it looks like you could do this kind of game much more easily in Twine (http://www.gimcrackd.com/etc/src/). Of course, if you're doing this to learn Python, that's not very useful :smallwink:

To begin with, I would recommend trying to do something smaller - just implement one option, make sure you have the syntax right, before filling out a long list like you have here.

Incidentally, I feel you could probably structure your code more clearly than a bunch of if statements. You might be better off (more easy to maintain/extend the code) having a data structure of commands and associated outputs.

factotum
2013-08-03, 03:35 PM
I'm not overly familiar with Python either, but one thing I *do* know about it is that indenting is part of the syntax of the language, so could it be a problem with the lack of indenting in your code?

Gligarman2
2013-08-03, 04:30 PM
Thanks. You guys were quite helpful.

lesser_minion
2013-08-03, 04:51 PM
It looks like you're using is incorrectly. is is used to test object identity, when you actually want to test for equivalence.

But that's a potential bug, not an error. I'm afraid I don't know Python syntax that well either.


I'm not overly familiar with Python either, but one thing I *do* know about it is that indenting is part of the syntax of the language, so could it be a problem with the lack of indenting in your code?

That's because it was posted without [code] tags, I think, not because it wasn't originally indented.