Alexander Quest wrote:
Hello- I am running Python v 3.1.1. As an exercise, I wrote a simple coin
flipper program, where the computer flips a coin 100 times and then prints
out the number of heads and tails. My program crashes immediately if I run
it normally through the command line, but if I go to "Run- Run Module," it
seems to work just fine. I can't seem to figure out why. I've pasted the
relevant code below- any help will be greatly appreciated. Thanks!


What do you mean, "crashes"? Do you get a segmentation error? A Python traceback? Computer hangs and you have to restart to recover? Something else?

What do you mean, "run it normally through the command line"?

What operating system are you using? What command are you using on the command line?

Since I love guessing games, I'm going to take a wild stab in the dark that you're using Linux, and you're done something like this:

[steve@sylar ~]$ echo "print('spam')" > spam.py  # make a Python script
[steve@sylar ~]$ cat spam.py
print('spam')
[steve@sylar ~]$ chmod u+x spam.py  # make it executable
[steve@sylar ~]$ ./spam.py
./spam.py: line 1: syntax error near unexpected token `'spam''
./spam.py: line 1: `print('spam')'

That's because you're trying to run it as a shell script. You need to add a hash-bang line to the file, or run it with Python:

[steve@sylar ~]$ python3 spam.py
spam


If that's not what you are doing, then we'll need more information to solve the problem.



--
Steven
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to