Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Βad Input on line 12
#1
Why does it not work Wall Wall

class JetPy:
  class Objects():
    def __init__(self, pos, size):
      self.pos = pos
      self.size = size
      
    def project(self):
      import turtle
      p = turtle.Turtle()
      p.goto(self.pos)
      p.setheading(0)
      for i in range(4):
	    if c % 2 == 1:
          p.forward(self.pos[0])
        else:
          p.forward(self.pos(1))
        p.right(90)
      
ex = JetPy.Objects((0, 0), (15, 15))
ex.project()
and it ends up doing this:

Error:
ParseError: bad input on line 12
Reply
#2
It looks this is error generated from some non-standard IDE. Probably online IDE?

I get
Error:
Traceback (most recent call last): File "***", line 20, in <module> ex.project() File "***", line 13, in project if c % 2 == 1: ^ NameError: name 'c' is not defined
There are multiple errors though. Next one, when you replace c with i would be
Error:
Traceback (most recent call last): File "***", line 20, in <module> ex.project() File "***", line 26, in project p.forward(self.pos(1)) ^^^^^^^^^^^ TypeError: 'tuple' object is not callable
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
Of course, one should note this nested structure is odd - why class within class? also all imports should be at the top


import turtle
class JetPy:
    def __init__(self, pos, size):
        self.pos = pos
        self.size = size
       
    def project(self):
        p = turtle.Turtle()
        p.goto(self.pos)
        p.setheading(0)
        for i in range(4):
            if i % 2 == 1:
                p.forward(self.pos[0])
            else:
                p.forward(self.pos[1])
            p.right(90)
       
ex = JetPy((0, 0), (15, 15))
ex.project()
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
#4
I want to make my first module
Reply
#5
That is not how modules are created, nor is it what a module is. Modules are files, not classes. If you want Objects to be a class in the JetPy module, write the class in a file named JetPy.py

However, the convention for naming modules is to use all lowercase, so your module should be named jetpy.
Reply
#6
tank you

i finally made my first module :)
Dance Dance Dance Dance Dance Dance Dance Dance Dance Dance
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to revert back to a previous line from user input Sharkenn64u 2 916 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  Receive Input on Same Line? johnywhy 8 2,586 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  How to input & output parameters from command line argument shantanu97 1 3,589 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  How to make input come after input if certain line inserted and if not runs OtherCode Adrian_L 6 4,612 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
  Multi-line console input lizze 4 3,592 Dec-26-2020, 08:10 AM
Last Post: lizze
  bad input line 3 how t fix it youssef210 2 3,842 Aug-27-2020, 04:57 PM
Last Post: nilamo
  Line charts error "'isnan' not supported for the input types," issac_n 1 3,128 Jul-22-2020, 04:34 PM
Last Post: issac_n
  Taking Multiple Command Line Argument Input bwdu 6 7,001 Mar-29-2020, 05:52 PM
Last Post: buran
  How to make input goto a different line mxl671 2 3,297 Feb-04-2020, 07:12 PM
Last Post: Marbelous
  command line input (arg parse) and data exchange Simba 7 6,194 Dec-06-2019, 11:58 PM
Last Post: Simba

Forum Jump:

User Panel Messages

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