Skip to content

Instantly share code, notes, and snippets.

"""
Make a copy of square() and change the name to polygon()
Add another parameter named n and modify the body ...
so it draws an n-sided regular polygon.
Hint: The exterior angles of an n-sided regular polygon are 360/n degrees.
import turtle
def square(t, length):
"""
Write a function called square() that ...
takes a parameter named t, which is a turtle.
It should use the turtle to draw a square.
import turtle
bob = turtle.Turtle()
square(bob)
turtle.mainloop() """
<?php
/**
* Replace
* {b} abc {/b} with:
* <b> abc </b>
* Use preg_replace() function
*/
$str = "{b} abc {/b}";
/**
* This code will throw an Exception Error
* Correct the error line
*/
class App {
public static void main(String[] args) {
/**
* SOLUTION
/**
* Import libraries required by the following code
*/
/**
* SOLUTION
*/
import java.util.List;
import java.util.ArrayList;
<?php
/**
* Define class constructor and ...
* Display the constructor method name
*/
$obj = new A();
class A
{
/**
* Write constructor and method for Output class.
* The output() prints the <name> instance variable
*/
class App {
public static void main(String[] args) {
Output o = new Output("John");
o.output(); // John
}
}
/**
* Define Dog class which
* Dog class must implement the correct class
*/
class App {
public static void main(String[] args) {
Dog d = new Dog();
d.bark(); // The dog is barking
}
}
/**
* Define abstact class Animal
* Class Animal contains two methods, eat() and showName()
* One of the method is abstract
*/
class App {
public static void main(String[] args) {
Dog d = new Dog();
d.setName("MyDog");
System.out.println(d.name); // MyDog
/**
Define MyMath.floor() method using java.lang.math method
class App {
public static void main(String[] args) {
double n = MyMath.floor(12.3);
System.out.print(n); // 12.0
}
}
*/