Python 使用 turtle 库
```python
import turtle
创建绘图窗口
window = turtle.Screen()
window.title("Draw a Square")
window.bgcolor("white")
创建画笔
pen = turtle.Turtle()
pen.color("black")
pen.pensize(3)
绘制正方形的四条边
for _ in range(4):
pen.forward(100) 移动画笔向前
pen.right(90) 调整画笔角度
关闭绘图窗口
window.mainloop()
```
Java 使用 Scanner 和 System 输出
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要打的边长数:");
int a = sc.nextInt();
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
System.out.print("* ");
}
System.out.println();
}
}
}
```
C++ 使用标准输入输出
```cpp
include
int main() {
int a;
std::cout << "请输入你要打的边长数: ";
std::cin >> a;
for (int i = 0; i < a; i++) {
for (int j = 0; j < a; j++) {
std::cout << "* ";
}
std::cout << std::endl;
}
return 0;
}
```
JavaScript 使用 HTML5 Canvas
```html