General question about the Python course.

So after the Computer Science Fundamentals course I decided to take the Python course as a compliment to the Java program I'm already learning at school. I have a question about the whole drawing thing. It tells me that to import the turtle you have to type in "from turtle import *", to move forward you type something like "forward(300)" and to turn left a certain number of degrees you type "left(45)". I tried compiling the code on an online compiler (onlinegdb.com). It didn't work. I then tried downloading Python for my computer, and it didn't work as well. When I tried to find the code online, it gave me a different format on how to do everything. For example, if you want to get the turtle into your Python you write "import turtle" instead of "from turtle import *", to move forward you write "turtle.forward(200)" instead of "forward(200) and to turn left you write "turtle.left(45)" instead of "left(45)". This may discrepancy may be tiny or it may be huge, I may just be really dumb and this different syntax's be something common in computer science. But I'm new to most computer science concepts, so if anyone can explain to me why this is the case and which one is correct it would be very much appreciated. :)

Note by Okky Prabowo
4 weeks, 1 day ago

No vote yet
1 vote

  Easy Math Editor

This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.

When posting on Brilliant:

  • Use the emojis to react to an explanation, whether you're congratulating a job well done , or just really confused .
  • Ask specific questions about the challenge or the steps in somebody's explanation. Well-posed questions can add a lot to the discussion, but posting "I don't understand!" doesn't help anyone.
  • Try to contribute something new to the discussion, whether it is an extension, generalization or other idea related to the challenge.
  • Stay on topic — we're all here to learn more about math and science, not to hear about your favorite get-rich-quick scheme or current world events.

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold

- bulleted
- list

  • bulleted
  • list

1. numbered
2. list

  1. numbered
  2. list
Note: you must add a full line of space before and after lists for them to show up correctly
paragraph 1

paragraph 2

paragraph 1

paragraph 2

[example link](https://brilliant.org)example link
> This is a quote
This is a quote
    # I indented these lines
    # 4 spaces, and now they show
    # up as a code block.

    print "hello world"
# I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
MathAppears as
Remember to wrap math in \( ... \) or \[ ... \] to ensure proper formatting.
2 \times 3 2×3 2 \times 3
2^{34} 234 2^{34}
a_{i-1} ai1 a_{i-1}
\frac{2}{3} 23 \frac{2}{3}
\sqrt{2} 2 \sqrt{2}
\sum_{i=1}^3 i=13 \sum_{i=1}^3
\sin \theta sinθ \sin \theta
\boxed{123} 123 \boxed{123}

Comments

Sort by:

Top Newest

Hello Okky, Let's kill this topic together. Let's say you have written a file named math.py and you have written two custom functions in this file namely pow(a, b) and round(a). And you want to make use of these functions in a new python file named main.py. Now you have two ways to do that 1. import math and then use functions like math.pow(a, b) and round(a). 2. from math import math, round and then use functions like pow(a, b) and round(a).

Also from math import * imports everything that was defined in math.py. But this is not used as it hinders production level code development. For example: Suppose that you have two independent modules math.py and math1.py. Now, math.py has a custom function subtract that takes in two arguments (a and b) and return a - b. What math1.py's subtract does is return (b -a). And you import both files in main.py .Then you will get an error that function definitions are common.

I think you must ask programming related questions on StackOverflow. Read this great answer: https://stackoverflow.com/questions/710551/use-import-module-or-from-module-import. Also read the official documentation here: https://docs.python.org/3/tutorial/modules.html

shivam jalotra - 4 weeks ago

Log in to reply

I think I get it. So from module import * imports everything that is in math.py, while import math only imports the functions?

Okky Prabowo - 4 weeks ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...