Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i need help with an error
#11
I tryed this code, same error. I don't get it why it works when I write it first time but whe I try to test my code from the file.py I get that error.

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import turtle
>>> my_turtle = turtle.Turtle()
>>> my_turtle.speed(0)
>>> def square(length, angle):
	for i in range(4):
		my_turtle.forward(length)
		my_turtle.right(angle)

		
>>> for i in range(150):
	square(100,90)
	my_turtle.right(11)

	
>>> 
Reply
#12
(May-30-2017, 04:06 PM)buran Wrote:
import turtle
my_turtle = turtle.Turtle()
my_turtle.speed(0)
def square(lenght,angle):
    for i in range(4):
        my_turtle.forward(lenght)
        my_turtle.right(angle)
 
         
for i in range(150):
    square(100,90)
    my_turtle.right(11)
 
when you write your file it should like this above. everything else is output from the interactive prompt, it's not part of the code.
You can write the code in your favorite text editor or more advanced IDE. For start you can use also IDLE, but it's not considered good IDE

did you even care to read my post????? Why do you waste our time when you don't read and follow what you are told?
Reply
#13
Even if I try to run something like print("Hello, World") I got the same error

Sorry mate, I am trying a lot of codes. I tryed your code too, I just forgot to mention because I just don't know what to do anymore. I am not wasting your time because I don't want to waste my tine neither.

Same error :

>>> import turtle
>>> my_turtle = turtle.Turtle()
>>> my_turtle.speed(0)
>>> def square(length, angle):
	for i in range(4):
		my_turtle.forward(length)
		my_turtle.right(angle)

		
>>> for i in range(150):
	square(100,90)
	my_turtle.right(11)

Even this code got me to the same error:

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> print ("Hello, World")
Reply
#14
(May-30-2017, 04:06 PM)Larz60+ Wrote: no indent on 1st for loop
length spelling wrong, but done twice so ok

call to square and my_turtle.right not indented
code should look like:

>>> import turtle
>>> my_turtle = turtle.Turtle()
>>> my_turtle.speed(0)
>>> def square(lenght,angle):
        for i in range(4):
            my_turtle.forward(lenght)
            my_turtle.right(angle)
 
         
>>> for i in range(150):
        square(100,90)
        my_turtle.right(11)

Curious about this post, I took this exact code and ran it (I removed the output markers via Notepad++ and realigned the rest of the code). I am using Python 3.6.1 and this worked flawlessly.

OP, I would take a step back, take a deep breath and focus. I am a new programmer, but if it gets to the point where you are too frustrated to focus these guys (and gals) can't help you. I followed their advice, it works.

Have you uninstalled Python and reinstalled? Are you using cmd or cmder? Did you exit() pryor to trying to run the .py? This code works. Where in the steps provided are you running into problems?
Reply
#15
one last attempt and I give up.
This
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
is NOT part of the code. It's part of the output in the interactive python prompt. It MUST NOT be in your py file!

This

>>>
is the prompt, so it MUST NOT present in your py file.
Reply
#16
i think you need to understand the different methods of executing python
https://python-forum.io/Thread-Basic-How...ython-code
Recommended Tutorials:
Reply
#17
(May-30-2017, 05:11 PM)RodNintendeaux Wrote: Curious about this post, I took this exact code and ran it (I removed the output markers via Notepad++ and realigned the rest of the code). I am using Python 3.6.1 and this worked flawlessly.
OP also says it works first time. Then he "save it" as file and gets SynatxError. From his description obviously he saves everything in the py file., Incl. the header as well as >>>
Reply
#18
(May-30-2017, 05:23 PM)buran Wrote:
(May-30-2017, 05:11 PM)RodNintendeaux Wrote: Curious about this post, I took this exact code and ran it (I removed the output markers via Notepad++ and realigned the rest of the code). I am using Python 3.6.1 and this worked flawlessly.
OP also says it works first time. Then he "save it" as file and gets SynatxError. From his description obviously he saves everything in the py file., Incl. the header as well as >>>

Being new this is interesting to me. Are there any text editors or errors within them that could offset the .py extension with some other setting? It may be a software issue causing the error. I just opened Ubuntu into a virtual environment and the same code works flawlessly. I can't replicate this syntax error.
Reply
#19
(May-30-2017, 05:26 PM)RodNintendeaux Wrote: I can't replicate this syntax error.

OP is using Windows and IDLE
If you have access, save this, as is, in a py file:
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> print ("Hello, World")
and run it.
Reply
#20
Here how IDLE work with Pictures.
This is interactive console,it's what always open first.
[Image: hje21L.jpg]

To save it as code remove >>> and give it a file like hello.py(save it).
[Image: Wn7asS.jpg]
Reply


Forum Jump:

User Panel Messages

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