Python Forum
My first day coding (ever) :/
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first day coding (ever) :/
#1
Hey, I have just started reading 'Python for programers' and theres an example in the textbook that gets us to execute a script. But the command doesn't work. After looking on Git hub, i see that the author of the book (Paul Deitel) has posted a new, correct command. But it is still not working i keep getting a "syntax error". What am I doing wrong? (p.s. sorry, i am not sure how to upload a photo). Maybe someone else could see if it works for them. Here is the page https://github.com/pdeitel/IntroToPython
Reply
#2
I didn't run the code but from what I see, you need at least python 3.6 to run it. What is your version of python?
Reply
#3
Thanks for your reply. I'm using python 3.8.3. So i am still not sure of the issue.
Reply
#4
Can you post the complete error traceback between error tags?
Reply
#5
Look here if you use Windows.
Here a quick run you can look at,i clone Repo and run RollDieDynamic.py
G:\div_code
λ git clone https://github.com/pdeitel/IntroToPython.git
Cloning into 'IntroToPython'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 1029 (delta 0), reused 1 (delta 0), pack-reused 1026
Receiving objects: 100% (1029/1029), 13.73 MiB | 3.25 MiB/s, done.
Resolving deltas: 100% (731/731), done.
Checking connectivity... done.
Checking out files: 100% (1136/1136), done.

G:\div_code
λ cd IntroToPython\

G:\div_code\IntroToPython (master)
λ ls
IntroToPythonCover.png  README.md  examples/

G:\div_code\IntroToPython (master)
λ cd examples\

G:\div_code\IntroToPython\examples (master)
λ cd ch01

G:\div_code\IntroToPython\examples\ch01 (master)
λ ls
RollDieDynamic.py  snippets_ipynb/

G:\div_code\IntroToPython\examples\ch01 (master)
λ python RollDieDynamic.py
ModuleNotFoundError: No module named 'seaborn'

# Install seaborn
G:\div_code\IntroToPython\examples\ch01 (master)
λ pip install seaborn
Collecting seaborn
  Downloading seaborn-0.10.1-py3-none-any.whl 
....
Successfully installed scipy-1.5.2 seaborn-0.10.1

# Run need command line arguments
G:\div_code\IntroToPython\examples\ch01 (master)
λ python RollDieDynamic.py 5 2
[Image: BhDGGS.png]
You need to install some stuff,as matplotlib and seaborn.
This book also do a lot in Jupyter Notebook.
So do install JupyterLab.
I use cmder here,but command is same in cmd.
You may need Git,to clone Repo as i do.
Reply
#6
Hey thanks for the help, really appreciate it. I use mac btw. Also i don't understand most of the things you said sorry.

here is what i did:

Last login: Wed Aug 26 11:24:34 on console

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
(base) Jesses-iMac:~ jessefarquhar$ ipython
Python 3.8.3 (default, Jul  2 2020, 11:26:31) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: cd ~/documents/pythonforprogrammers-master/examples/ch01                
/Users/jessefarquhar/Documents/PythonForProgrammers-master/examples/ch01

In [2]: ipython -i rolldiedynamic.py 6000 1                                     
  File "<ipython-input-2-eeab42d97e89>", line 1
    ipython -i rolldiedynamic.py 6000 1
               ^
SyntaxError: invalid syntax


In [3]:  
Reply
#7
Now you try to run command in interactive shell,that command is meant to be run from command line(Terminal Mac).
So these two the give the same output image as shown if i run them from command line.
python RollDieDynamic.py 5 2
ipython Aerodynamically 5 2
On Mac the ipython is the same way,may need python3 if run from Python.
python3 RollDieDynamic.py 5 2
Also pip most work check with pip -V or pip3 -V command line.
The install eg JupyterLab is like this.
pip3 install jupyterlab
Reply
#8
Thanks, i just needed to run it in the terminal rather than interactive shell. How did you know it was meant for the terminal rather than the interactive shell?
Reply
#9
(Aug-27-2020, 01:03 AM)jessefarquhar Wrote: How did you know it was meant for the terminal rather than the interactive shell?
Code uses sys.argv which is used to take arguments from command line and pass it to code.
Here i run in colab notebook now you see that have take away sys.argv and give values in code.
Also added %matplotlib inline to show plot in Notebook and not a own window.

Google Colab is fine and free way to run Notebooks no install just use and run.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020