Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Useless Newbee
#1
Hi I've just started trying to teach myself Python using one of the "for Dummies" books, I'me using VS Code through Anaconda running Python 3.7. I've attempted to make a Magic 8 Ball Program and I'm showing no errors in my code yet it doesn't run. It says there is a syntax error.

import random
question = input("Ask the Magic 8 Ball a Question")
answer = random.randint(1,8)
if answer == 1:
    print("Definately")
elif answer == 2:
    print("Looking good")
elif answer == 3:
    print("You can count on it")
elif answer == 4:
    print("Ask me again leter")
elif answer == 5:
    print("I'm not sure you really want ot know")
elif answer == 6:
    print("I wouldn't bet money on it")
elif answer == 7:
    print(" Not a chance")
elif answer == 8:
    print("I've heard that's a no")
else:
    print("That's not a question")
print ("The End")
This is the response in terminal:

>>> & C:/Users/my user/AppData/Local/Continuum/anaconda3/python.exe "c:/Users/my user/Google Drive/Python/Code Library/Magic 8 Ball.py"
File "<stdin>", line 1
& C:/Users/my users/AppData/Local/Continuum/anaconda3/python.exe "c:/Users/my users/Google Drive/Python/Code Library/Magic 8 Ball.py"
^
SyntaxError: invalid syntax


I'm sure it's something simple and basic, however that is where my knowledge is currently. Any help would be great fully received.
Reply
#2
>>> indicates you are in python interactive mode. you must run your code from terminal.
read https://python-forum.io/Thread-Anaconda-...run-Python
https://python-forum.io/Thread-How-to-Ex...ython-code
Also read how to convert huge if block into dict: https://python-forum.io/Thread-if-struct...dictionary
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
right got it, now all i need to do is figure out the formatting, inserting spaces and new lines ect.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  file handling Newbee question middlecope 2 745 Jan-18-2023, 03:09 PM
Last Post: middlecope
  Newbee Question chas777 4 2,204 Apr-01-2020, 06:52 PM
Last Post: chas777
  Preventing useless multiple disk writes Steffenwolt 9 4,580 Jul-28-2018, 06:39 PM
Last Post: gontajones
  Newbee - substing of column andrewjmdata 2 2,654 Feb-17-2018, 07:04 PM
Last Post: andrewjmdata

Forum Jump:

User Panel Messages

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