-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenges.py
173 lines (170 loc) · 90.2 KB
/
challenges.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
data = {
'python': {
'1': """print "Hello World"⭔print 7⭔print 5 + 4⭔print "5 + 4"⭔print "5" + "4"⭔print 5 * 2⭔print 24 / 6⭔print 10 - 3⭔print 2 * 4 - 3⭔print 2 * (4 - 3)⭔print "ROAR! " * 5⭔print "Add a leading # to make one line be comment"⭔print "Comments are just for you, they will be ignored when the code runs"⭔""",
'2': """a = 1⭔b = 2⭔print a⭔print a + b⭔c = 1.5⭔print a + b + c⭔print 1 < 2⭔print 3 == 3⭔print 4 == 3⭔print 3 > 4⭔print 1 < 2 and 3 < 4⭔print 3 < 3 or 3 == 3⭔print 3 <= 3⭔print not 1 < 2⭔s1 = "Hello"⭔print s1⭔s2 = "15"⭔print s2 * 2⭔print int(s2) * 2⭔s3 = "3.14"⭔print s3 * 2⭔print float(s3) * 2⭔""",
'3': """s = "hello world"⭔print "hello" + " , " + "" + " !"⭔print len(s)⭔print s.capitalize()⭔print s.count("h")⭔print s.count("o")⭔print s.count("world")⭔print s.endswith("orld")⭔print s.endswith("ello")⭔print s.startswith("he")⭔print s.upper()⭔print s.lower()⭔print s.title()⭔print s.split()⭔print s.find("he")⭔print s.find("world")⭔print s.find("py")⭔""",
'4': """name = raw_input("Enter your name")⭔print "Hello", name⭔age = raw_input("Enter your age")⭔print "You are", age, "years old"⭔color = raw_input("Enter your favorite color")⭔print "Your favorite color is", color⭔number = raw_input("What is your favorite number⭔")⭔print "Your favorite number is", number⭔multiplied = int(number) * 2⭔print "Your favorite number doubled is", multiplied⭔""",
'5': """weather = "sunny"⭔if weather == "sunny":⭔print "We will go on a picnic!"⭔print "Hooray!"⭔import time⭔time.sleep(0.5)⭔age = int(raw_input("Enter your age:"))⭔if age >= 13:⭔print "You can watch this movie"⭔else:⭔print "Sorry, you can't watch this movie"⭔time.sleep(0.5)⭔score = float(raw_input("how would you rate this movie⭔ (1⭔5):"))⭔if score >= 4.5:⭔print "You like it very much"⭔elif score >= 3.5:⭔print "You like it"⭔elif score >= 2.5:⭔print "You think it is an average movie"⭔else:⭔print "You don't like it :("⭔""",
'6': """shopping_list = ["milk", "apple juice", "beacon", "tomato"]⭔print shopping_list, "has", len(shopping_list), "items"⭔shopping_list.append("grape")⭔shopping_list.append("orange")⭔print shopping_list⭔print shopping_list[0]⭔print shopping_list[2]⭔shopping_list.extend(["eggs", "bagel"])⭔print shopping_list⭔shopping_list.remove("milk")⭔print shopping_list⭔shopping_list.remove("beacon")⭔print shopping_list⭔shopping_list.sort()⭔print "After sorted:"⭔print shopping_list⭔mylist = [1, 2, "apple", 3.14, "circle"]⭔print mylist⭔""",
'7': """numbers = [12, 3, 25, 36]⭔print numbers[0]⭔print numbers[1]⭔print numbers[2]⭔print numbers[3]⭔print "* for-loop demo:"⭔for index in range(len(numbers)):⭔print numbers[index]⭔for num in numbers:⭔print num⭔for i in range(10):⭔print "Hello "⭔print "* while-loop demo:"⭔i = 0⭔while i < len(numbers):⭔print numbers[i]⭔i = i + 1⭔counter = 0⭔while counter < 10:⭔print "Hello "⭔counter = counter + 1⭔print "* break demo:"⭔for i in range(10):⭔if i == 6:⭔break⭔print i⭔print "* continue demo:"⭔for i in range(10):⭔if i == 6:⭔continue⭔print i⭔""",
'8': """number = raw_input("Enter a number")⭔decimal = int(number)⭔binary = ""⭔while decimal > 0:⭔remainder = decimal % 2⭔binary = str(remainder) + binary⭔decimal = decimal / 2⭔print number, "in binary is", binary⭔""",
'9': """number = raw_input("Enter a number")⭔decimal = int(number)⭔hexadecimal = ""⭔while decimal > 0:⭔remainder = decimal % 16⭔if remainder < 10:⭔hexadecimal = str(remainder) + hexadecimal⭔elif remainder == 10:⭔hexadecimal = "A" + hexadecimal⭔elif remainder == 11:⭔hexadecimal = "B" + hexadecimal⭔elif remainder == 12:⭔hexadecimal = "C" + hexadecimal⭔elif remainder == 13:⭔hexadecimal = "D" + hexadecimal⭔elif remainder == 14:⭔hexadecimal = "E" + hexadecimal⭔else:⭔hexadecimal = "F" + hexadecimal⭔decimal = decimal / 16⭔print number, "in hexadecimal is", hexadecimal⭔""",
'10': """import time⭔print "Timezone:", time.tzname⭔for i in range(5):⭔print time.asctime()⭔time.sleep(1)⭔print "-" * 20⭔import random⭔numbers = [1, 2, 3, 4, 5]⭔print random.choice(numbers)⭔newNumber = random.randint(10, 20)⭔numbers.append(newNumber)⭔print numbers⭔random.shuffle(numbers)⭔print numbers⭔""",
'11': """import random⭔import time⭔x = random.randint(1, 50)⭔chances = 10⭔numGuesses = 0⭔guess = 0⭔while numGuesses < chances:⭔guess = raw_input("Guess a number between 1 and 100")⭔guess = int(guess)⭔if guess > 100 or guess < 1:⭔print guess, "is out of range"⭔numGuesses += 1⭔elif guess > x:⭔print guess, "is too high"⭔numGuesses += 1⭔elif guess < x:⭔print guess, "is too low"⭔numGuesses += 1⭔else:⭔print "Correct!"⭔break⭔time.sleep(0.5)⭔if guess != x:⭔print "The correct number was", x⭔""",
'12': """import time⭔choice = ""⭔total = 0.0⭔while choice != "done":⭔choice = raw_input("burger, pizza or cookies."⭔+ " type 'done' when you are done")⭔choice = choice.lower()⭔if choice == "burger":⭔total = total + 4.50⭔elif choice == "pizza":⭔total = total + 2.0⭔elif choice == "cookies":⭔total = total + 2.50⭔elif choice == "done":⭔break⭔else:⭔print "We don't have", choice⭔time.sleep(0.5)⭔continue⭔print "Your choice:", choice⭔time.sleep(0.5)⭔print "Your total is $" + str(total)⭔""",
'13': """import time⭔for multiplier in range(1, 5):⭔for i in range(1, 10):⭔print i, "x", multiplier, "=", i * multiplier⭔print "-" * 10⭔time.sleep(1)⭔numStars = int(raw_input("How many stars do you want in one line⭔"))⭔numLines = int(raw_input("How many lines do you want⭔"))⭔for i in range(numLines):⭔for j in range(numStars):⭔print "*",⭔print ""⭔print "-" * 10⭔time.sleep(1)⭔numBlocks = int(raw_input("How many star blocks do you want⭔"))⭔for k in range(numBlocks):⭔print "[block %s]:" % k⭔for i in range(numLines):⭔for j in range(numStars):⭔print "*",⭔print ""⭔""",
'14': """from random import randint⭔myList = []⭔for counter in range(10):⭔myList.append(randint(1, 100))⭔print "Before sorting:"⭔print myList⭔iterCount = 1⭔for i in range(len(myList)):⭔smallest = i⭔for j in range(i, len(myList)):⭔if myList[j] < myList[smallest]:⭔smallest = j⭔if smallest != i:⭔temp = myList[i]⭔myList[i] = myList[smallest]⭔myList[smallest] = temp⭔print "Iteration", iterCount, ":", myList⭔iterCount = iterCount + 1⭔print "After sorting:"⭔print myList⭔""",
'15': """from random import randint⭔myList = []⭔for counter in range(10):⭔myList.append(randint(1, 100))⭔print "Before sorting:"⭔print myList⭔iterCount = 1⭔for index in range(1, len(myList)):⭔currValue = myList[index]⭔position = index⭔while position > 0 and myList[position - 1] > currValue:⭔myList[position] = myList[position - 1]⭔position = position - 1⭔myList[position] = currValue⭔print "Iteration", iterCount, ":", myList⭔iterCount += 1⭔print "After sorting:"⭔print myList⭔""",
'16': """myDict = {⭔"hello": "an expression of greeting",⭔"world": "everything that exists anywhere"⭔}⭔print "Query - hello:", myDict["hello"]⭔menu = {⭔"milk": 3.72,⭔"bacon": 4.98,⭔"burger": 3.5⭔}⭔print "Price of bacon is", menu["bacon"]⭔if menu.has_key("milk"):⭔print "We have milk"⭔else:⭔print "Sorry, we don't have milk"⭔if "milk" in menu:⭔print "We have milk"⭔print menu.keys()⭔print "* Menu:"⭔for (key, value) in menu.items():⭔print key, ":", value⭔menu["milk"] = 3.82⭔menu["sausage"] = 4.94⭔print menu⭔menu.pop("burger")⭔print menu⭔""",
'17': """calories = {⭔"apple": 95,⭔"banana": 105,⭔"pineapple": 402,⭔"orange": 45,⭔"mango": 201,⭔}⭔import time⭔answer = ""⭔totalCalories = 0⭔while answer != "done":⭔answer = raw_input("What do you want⭔\\n %s \\nInput 'done' to finish" %⭔calories.keys())⭔answer = answer.lower()⭔if answer in calories:⭔print "You choose", answer⭔totalCalories += calories[answer]⭔elif answer == "done":⭔continue⭔else:⭔print "Sorry, we don't have", answer⭔time.sleep(0.2)⭔print "Total calories:", totalCalories⭔""",
'18': """def printInfo():⭔print "John"⭔print "Address: 10 xyz lane"⭔print "Favorite color: blue"⭔print "Favorite coding language: "⭔print⭔printInfo()⭔printInfo()⭔def printInfo(name, addr, color, lang):⭔print name⭔print "Address:", addr⭔print "Favorite color:", color⭔print "Favorite coding language:", lang⭔print⭔printInfo("Bob", "11 abc Lane", "green", "Java")⭔printInfo("Alice", "236 meadow dr", "pink", "Scratch")⭔def add(a, b):⭔return a + b⭔c = add(1, 2)⭔print "sum is:", c⭔print⭔def checkPlease(price, taxRate, tipsRate):⭔tax = price * taxRate⭔tips = price * tipsRate⭔total = price + tax + tips⭔return total⭔print "Your total is:", checkPlease(13.5, 0.05, 0.15)⭔""",
'19': """speed = 10⭔def speedUp1():⭔print "I am going to change the speed"⭔speed = 20⭔speedUp1()⭔print "After calling speedUp1, current speed is:", speed⭔print⭔def speedUp2():⭔global speed⭔print "I declare speed is the global one"⭔print "I am going to really change the speed"⭔speed = 20⭔speedUp2()⭔print "After calling speedUp2, current speed is:", speed⭔""",
'20': """def fibonacci(num):⭔if num == 0:⭔return 0⭔if num == 1:⭔return 1⭔return fibonacci(num-2) + fibonacci(num-1)⭔for i in range(10):⭔print fibonacci(i),⭔print⭔def power(base, exp):⭔if exp == 0:⭔return 1⭔return base * power(base, exp-1)⭔print "2^5 is:", power(2, 5)⭔print "3^2 is:", power(3, 2)⭔print "4^5 is:", power(4, 5)⭔""",
'21': """import math⭔class Circle:⭔def __init__(self, radius):⭔self.radius = radius⭔def circumference(self):⭔return 2 * math.pi * self.radius⭔def area(self):⭔return math.pi * self.radius * self.radius⭔c1 = Circle(1.2)⭔print "Circle c1"⭔print "- radius:", c1.radius⭔print "- circumference:", c1.circumference()⭔print "- area:", c1.area()⭔c2 = Circle(2.5)⭔print "Circle c2"⭔print "- radius:", c2.radius⭔print "- circumference:", c2.circumference()⭔print "- area:", c2.area()⭔""",
'22': """class Person:⭔def __init__(self, name, birthyear):⭔self.name = name⭔self.birthyear = birthyear⭔def printInfo(self):⭔print "Name:", self.name⭔print "Year of birth:", self.birthyear⭔class Student(Person):⭔def __init__(self, name, birthyear, school):⭔Person.__init__(self, name, birthyear)⭔self.school = school⭔def printInfo(self):⭔Person.printInfo(self)⭔print "School:", self.school⭔class CollegeStudent(Student):⭔def __init__(self, name, birthyear, school, major):⭔Student.__init__(self, name, birthyear, school)⭔self.major = major⭔def printInfo(self):⭔Student.printInfo(self)⭔print "Major:", self.major⭔student1 = Student("Alice", 2000, "Meadow High School")⭔student1.printInfo()⭔print "-" * 10⭔student2 = CollegeStudent("Bob", 1996, "MIT", "Computer Science")⭔student2.printInfo()⭔""",
'23': """from turtle import Turtle⭔t = Turtle()⭔t.setposition(-200, 200)⭔t.forward(100)⭔t.right(90)⭔t.forward(80)⭔t.circle(40)⭔t.color("red")⭔t.circle(40, 180)⭔t.shape("turtle")⭔t.stamp()⭔t.forward(100)⭔t.setposition(0, 0)⭔t.goto(50, 50)⭔t.goto(100, 0)⭔t.goto(0, 0)⭔t.goto(0, -100)⭔t.goto(100, -100)⭔t.goto(100, 0)⭔t.setposition(40, -100)⭔t.goto(40, -50)⭔t.goto(60, -50)⭔t.goto(60, -100)⭔t.color("green")⭔t.setposition(50, -90)⭔""",
'24': """from turtle import Turtle⭔from random import randint⭔t = Turtle()⭔for counter in range(4):⭔t.forward(40)⭔t.right(90)⭔t.setposition(-100, -100)⭔for counter in range(50):⭔t.color(0, randint(0, 255), randint(0, 255))⭔t.forward(100)⭔t.right(115)⭔t.setposition(80, 120)⭔for counter in range(50):⭔t.color(randint(0, 255), randint(0, 255), randint(0, 255))⭔t.forward(90)⭔t.right(82)⭔""",
'25': """from turtle import Turtle⭔t = Turtle()⭔def hexagon(size):⭔for i in range(6):⭔t.forward(size)⭔t.right(60)⭔t.setposition(-150, 150)⭔hexagon(40)⭔t.setposition(150, 150)⭔hexagon(20)⭔t.setposition(-150, -150)⭔hexagon(50)⭔t.setposition(0, 0)⭔for i in range(6):⭔hexagon(30)⭔t.forward(30)⭔t.left(60)⭔""",
'26': """from turtle import Turtle⭔t = Turtle()⭔t.begin_fill()⭔for counter in range(4):⭔t.forward(80)⭔t.right(90)⭔t.end_fill()⭔t.setposition(-150, 150)⭔t.color("orange")⭔t.begin_fill()⭔for counter in range(6):⭔t.forward(80)⭔t.right(60)⭔t.end_fill()⭔t.setposition(-150, -100)⭔t.color("blue")⭔t.begin_fill()⭔for i in range(12):⭔t.forward(40)⭔t.right(30)⭔t.end_fill()⭔t.setposition(150, 100)⭔t.color("#339960")⭔t.begin_fill()⭔t.circle(40)⭔t.end_fill()⭔""",
'27': """from turtle import Turtle⭔t = Turtle()⭔t.width(1)⭔t.speed(10)⭔for j in range(3):⭔t.begin_fill()⭔for i in range(4):⭔t.forward(20)⭔t.right(90)⭔t.end_fill()⭔t.forward(20)⭔t.penup()⭔t.back(60)⭔t.left(90)⭔t.forward(20)⭔t.right(90)⭔t.pendown()⭔t.begin_fill()⭔for i in range(4):⭔t.forward(20)⭔t.right(90)⭔t.end_fill()⭔t.forward(20)⭔t.color("blue")⭔t.begin_fill()⭔for i in range(4):⭔t.forward(20)⭔t.right(90)⭔t.end_fill()⭔t.forward(20)⭔t.color("black")⭔t.begin_fill()⭔for i in range(4):⭔t.forward(20)⭔t.right(90)⭔t.end_fill()⭔t.forward(20)⭔t.penup()⭔t.back(60)⭔t.left(90)⭔t.forward(20)⭔t.right(90)⭔t.pendown()⭔for j in range(3):⭔t.begin_fill()⭔for i in range(4):⭔t.forward(20)⭔t.right(90)⭔t.end_fill()⭔t.forward(20)⭔""",
'28': """from turtle import Turtle⭔t = Turtle()⭔t.width(1)⭔t.speed(10)⭔def square(color):⭔t.color(color)⭔t.begin_fill()⭔for i in range(4):⭔t.forward(20)⭔t.right(90)⭔t.end_fill()⭔t.forward(20)⭔def nextRow(numSquares):⭔t.up()⭔t.back(numSquares * 20)⭔t.left(90)⭔t.forward(20)⭔t.right(90)⭔t.down()⭔for j in range(3):⭔square("black")⭔nextRow(3)⭔square("black")⭔square("blue")⭔square("black")⭔nextRow(3)⭔for j in range(3):⭔square("black")⭔""",
'29': """from turtle import Turtle⭔t = Turtle()⭔t.width(1)⭔t.speed(10)⭔side = 20⭔width = 3⭔def row(colors, numbers):⭔for i in range(len(colors)):⭔t.color(colors[i])⭔for j in range(numbers[i]):⭔t.begin_fill()⭔for k in range(4):⭔t.forward(side)⭔t.right(90)⭔t.end_fill()⭔t.forward(side)⭔t.up()⭔t.back(width * side)⭔t.left(90)⭔t.forward(side)⭔t.right(90)⭔t.down()⭔colors = ["black"]⭔numbers = [3]⭔row(colors, numbers)⭔colors = ["black", "blue", "black"]⭔numbers = [1, 1, 1]⭔row(colors, numbers)⭔colors = ["black"]⭔numbers = [3]⭔row(colors, numbers)⭔""",
'30': """from turtle import Turtle⭔t = Turtle()⭔t.width(1)⭔t.speed(10)⭔side = 20⭔width = 9⭔height = 9⭔white, black, red, darkred = 'white', 'black', 'red', 'darkred'⭔t.setposition(-(width * (side/2)), height * (side/2))⭔def row(pixels):⭔for (color, count) in pixels:⭔t.color(color)⭔for j in range(count):⭔t.begin_fill()⭔for k in range(4):⭔t.forward(side)⭔t.right(90)⭔t.end_fill()⭔t.forward(side)⭔t.penup()⭔t.back(width * side)⭔t.right(90)⭔t.forward(side)⭔t.left(90)⭔t.pendown()⭔row([(white, 2), (black, 2), (white, 1), (black, 2), (white, 2)])⭔row([(white, 1), (black, 1), (red, 2), (black, 1),⭔(red, 2), (black, 1), (white, 1)])⭔row([(black, 1), (red, 1), (white, 1), (red, 5), (black, 1)])⭔row([(black, 1), (red, 7), (black, 1)])⭔row([(black, 1), (darkred, 1), (red, 5), (darkred, 1), (black, 1)])⭔row([(white, 1), (black, 1), (darkred, 1),⭔(red, 3), (darkred, 1), (black, 1), (white, 1)])⭔row([(white, 2), (black, 1), (darkred, 1),⭔(red, 1), (darkred, 1), (black, 1), (white, 2)])⭔row([(white, 3), (black, 1), (darkred, 1), (black, 1), (white, 3)])⭔row([(white, 4), (black, 1), (white, 4)])⭔""",
'31': """from processing import *⭔def setup():⭔size(400, 400)⭔def draw():⭔background(0, 0, 0)⭔stroke(255)⭔line(0, 0, 50, 200)⭔fill(255, 0, 0)⭔ellipse(180, 80, 150, 100)⭔noStroke()⭔fill(0, 0, 255)⭔ellipse(180, 200, 150, 100)⭔fill(255, 160, 0)⭔rect(50, 300, 100, 70)⭔fill(0, 200, 0)⭔triangle(300, 200, 280, 380, 350, 350)⭔run()⭔""",
'32': """from processing import *⭔import math⭔width = 520⭔height = 360⭔radius = 16⭔theta = 0⭔dx = 0⭔steps = width / radius + 1⭔def setup():⭔global dx⭔size(width, height)⭔dx = float(TWO_PI / width) * radius⭔colorMode(HSB)⭔def draw():⭔global theta⭔background(0, 0, 0)⭔theta += 0.05⭔x = theta⭔hue = 0⭔for i in range(steps):⭔y = height / 2 + math.sin(x) * 70⭔x += dx⭔fill(hue, 255, 240)⭔ellipse(i * radius, y, radius, radius)⭔hue += 5⭔run()⭔""",
'33': """from processing import *⭔from random import randint⭔rotating_sun = 0⭔rotating_earth = 0⭔rotating_moon = 0⭔center_x = 250⭔center_y = 250⭔star_count = 150⭔stars = []⭔def setup():⭔size(540, 500)⭔for i in range(star_count):⭔x = randint(10, 530)⭔y = randint(10, 490)⭔width = randint(2, 8)⭔height = randint(2, 8)⭔color = randint(10, 100)⭔stars.append({⭔"x": x,⭔"y": y,⭔"width": width,⭔"height": height,⭔"color": color⭔})⭔def draw():⭔global rotating_sun, rotating_earth, rotating_moon⭔background(0, 0, 0)⭔for star in stars:⭔fill(star["color"])⭔ellipse(star["x"], star["y"], star["width"], star["height"])⭔noFill()⭔stroke(60, 60, 60)⭔arc(center_x, center_y, 140, 140, 0, 2*PI)⭔rotating_sun += -0.0001⭔rotating_earth += -0.005⭔rotating_moon += -0.06⭔noStroke()⭔translate(center_x, center_y)⭔rotate(rotating_sun)⭔fill(250, 0, 0)⭔ellipse(0, 0, 30, 30)⭔rotate(rotating_earth)⭔fill(100, 200, 250)⭔ellipse(70, 0, 13, 13)⭔translate(70, 0)⭔rotate(rotating_moon)⭔fill(250, 250, 0)⭔ellipse(10, 0, 4, 4)⭔run()⭔""",
'34': """from processing import *⭔font = None⭔def setup():⭔global font⭔size(500, 400)⭔font = createFont("Comic Sans MS", 30)⭔def draw():⭔background(0)⭔textFont(font)⭔fill(0, 240, 255)⭔textSize(40)⭔text("My Clock", 140, 120)⭔time = "%02d/%02d/%02d %02d:%02d:%02d" % \⭔(month(), day(), year(), hour(), minute(), second())⭔textSize(35)⭔fill(0, 255, 0)⭔text(time, 80, 220)⭔run()⭔""",
'35': """from processing import *⭔from math import sin⭔from random import randint⭔ballx = 30⭔bally = 30⭔rectx = 30⭔recty = 350⭔radius = 30⭔delay = 16⭔r = 100⭔g = 100⭔b = 100⭔def setup():⭔size(540, 400)⭔def draw():⭔global ballx, bally, rectx, recty, radius⭔background(r, g, b)⭔strokeWeight(10)⭔stroke(255)⭔fill(0, 121, 200)⭔ballx += float(mouse.x - ballx) / delay⭔bally += float(mouse.y - bally) / delay⭔radius = radius + sin(environment.frameCount / 4)⭔ellipse(ballx, bally, radius, radius)⭔strokeWeight(2)⭔fill(240, 150, 0)⭔rect(rectx, recty, 150, 30)⭔def mousePressed():⭔global r, g, b⭔r = randint(0, 150)⭔g = randint(0, 150)⭔b = randint(0, 150)⭔def keyPressed():⭔global rectx, recty⭔if keyboard.keyCode == UP:⭔recty -= 10⭔elif keyboard.keyCode == DOWN:⭔recty += 10⭔elif keyboard.keyCode == LEFT:⭔rectx -= 10⭔elif keyboard.keyCode == RIGHT:⭔rectx += 10⭔run()⭔""",
'36': """from processing import *⭔angle = 0⭔numLines = 20⭔width = 400⭔height = 400⭔def setup():⭔size(width, height)⭔colorMode(HSB)⭔def draw():⭔global angle⭔hue = 0⭔background(25)⭔strokeWeight(3)⭔translate(200, 200)⭔for i in range(numLines):⭔hue += i⭔stroke(hue, 255, 200)⭔rotate(PI / 30)⭔line(mouse.x-width/2, mouse.y-height/2, 0, -60)⭔angle += 0.0001⭔rotate(angle)⭔run()⭔""",
'37': """from processing import *⭔from random import choice⭔bunny = None⭔turtle = None⭔bunny_x = 10⭔turtle_x = 10⭔def setup():⭔global bunny, turtle⭔size(500, 400)⭔bunny = loadImage("https://speedcode.oyohub.com/img/bunny.png")⭔turtle = loadImage("https://speedcode.oyohub.com/img/turtle.png")⭔def draw():⭔background(255)⭔fill(20)⭔text("Use A and D key to move the turtle", 10, 20)⭔text("Use Left and Right arrow key to move the bunny", 230, 20)⭔image(turtle, turtle_x, 100, 60, 40)⭔image(bunny, bunny_x, 200, 60, 80)⭔noStroke()⭔fill(0, 200, 100)⭔rect(10, 140, 500, 10)⭔fill(240, 200, 0)⭔rect(10, 280, 500, 10)⭔textSize(30)⭔fill(0, 200, 100)⭔if turtle_x > 440:⭔text("Turtle won!", 170, 70)⭔exitp()⭔if bunny_x > 440:⭔text("Bunny won!", 170, 70)⭔exitp()⭔def keyPressed():⭔global turtle_x, bunny_x⭔if keyboard.key == "a":⭔turtle_x -= 10⭔elif keyboard.key == "d":⭔turtle_x += 10⭔if keyboard.keyCode == LEFT:⭔bunny_x -= 30⭔elif keyboard.keyCode == RIGHT:⭔if choice([0, 1, 2]) == 0:⭔bunny_x -= 30⭔else:⭔bunny_x += 30⭔run()⭔""",
'38': """from processing import *⭔counter = 0⭔currFrame = 0⭔x = 300⭔y = 10⭔speedY = 0⭔frames = []⭔def setup():⭔global p1, p2, p3, frames⭔size(540, 400)⭔background(0, 102, 0)⭔stepLeft = loadImage("https://speedcode.oyohub.com/img/frame1.png")⭔stand = loadImage("https://speedcode.oyohub.com/img/frame2.png")⭔stepRight = loadImage("https://speedcode.oyohub.com/img/frame3.png")⭔frames = [stepLeft, stand, stepRight, stand]⭔def draw():⭔global counter, currFrame, y⭔background(0, 102, 0)⭔fill(255)⭔text("Use up and down arrow key to move the character", 10, 20)⭔noStroke()⭔rect(290, 0, 40, 400)⭔if counter == 10:⭔currFrame = (currFrame + 1) % 4⭔counter = 0⭔counter += 1⭔if speedY:⭔y += speedY⭔image(frames[currFrame], x, y, 20, 30)⭔else:⭔stand = frames[1]⭔image(stand, x, y, 20, 30)⭔def keyPressed():⭔global speedY⭔if keyboard.keyCode == UP:⭔speedY = -1⭔if keyboard.keyCode == DOWN:⭔speedY = 1⭔def keyReleased():⭔global speedY⭔if keyboard.keyCode in [UP, DOWN]:⭔speedY = 0⭔run()⭔""",
'39': """from processing import *⭔import random⭔cat = None⭔catSoundList = [⭔"meow meow ⭔",⭔"where is my fish cake",⭔"pur pur pur ...",⭔]⭔class Cat:⭔def __init__(self, x, y, imgURL, soundList):⭔self.x = x⭔self.y = y⭔self.currSound = ""⭔self.img = loadImage(imgURL)⭔self.soundList = soundList⭔def moveLeft(self):⭔self.x -= 10⭔def moveRight(self):⭔self.x += 10⭔def startSpeaking(self):⭔if not self.currSound:⭔self.currSound = random.choice(self.soundList)⭔def endSpeaking(self):⭔self.currSound = ""⭔def draw(self):⭔image(self.img, self.x, self.y)⭔def speak(self):⭔if self.currSound:⭔fill(10)⭔textSize(20)⭔text(self.currSound, self.x, self.y - 10)⭔def setup():⭔global cat⭔size(540, 400)⭔background(255)⭔cat = Cat(200, 250,⭔"https://speedcode.oyohub.com/img/cat.png",⭔catSoundList)⭔def draw():⭔background(255)⭔fill(0)⭔text("Press space to speak", 200, 20)⭔cat.draw()⭔cat.speak()⭔def keyPressed():⭔if keyboard.keyCode == 32:⭔cat.startSpeaking()⭔def keyReleased():⭔if keyboard.keyCode == 32:⭔cat.endSpeaking()⭔run()⭔""",
'40': """from processing import *⭔width = 540⭔height = 450⭔ball = {⭔"x": 50,⭔"y": 50,⭔"radius": 10,⭔"vel_x": 20,⭔"vel_y": 20⭔}⭔r = 0⭔g = 100⭔b = 200⭔rinc = 2⭔ginc = 3⭔binc = 1⭔def setup():⭔size(width, height)⭔background(0, 0, 0)⭔def draw():⭔fill(r, g, b)⭔ellipse(ball["x"], ball["y"], 2*ball["radius"], 2*ball["radius"])⭔moveBall()⭔changeBallColor()⭔def moveBall():⭔ball["x"] += ball["vel_x"]⭔ball["y"] += ball["vel_y"]⭔if ball["x"] + ball["radius"] >= width or \⭔ball["x"] - ball["radius"] <= 0:⭔ball["vel_x"] = -ball["vel_x"]⭔if ball["y"] + ball["radius"] >= height or \⭔ball["y"] - ball["radius"] <= 0:⭔ball["vel_y"] = -ball["vel_y"]⭔def changeBallColor():⭔global r, g, b, rinc, ginc, binc⭔r += rinc⭔g += ginc⭔b += binc⭔if r >= 255 or r <= 0:⭔rinc = -rinc⭔if g >= 255 or g <= 0:⭔ginc = -ginc⭔if b >= 255 or b <= 0:⭔binc = -binc⭔run()⭔"""
},
'html': {
'1':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Boilerplate</title>⭔</head>⭔<body>⭔Hello world! A HTML tag is like a container. An opening tag starts with a⭔pointy bracket followed by a tag name and a closing tag starts with a pointy bracket and a forward slash followed by the tag name.⭔</body>⭔</html>⭔""",
'2':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Heading Tags</title>⭔</head>⭔<body>⭔<h1>Heading 1</h1>⭔<h2>Heading 2</h2>⭔<h3>Heading 3</h3>⭔<h4>Heading 4</h4>⭔<h5>Heading 5</h5>⭔<h6>Heading 6</h6>⭔</body>⭔</html>""",
'3':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Paragraph Tag</title>⭔</head>⭔<body>⭔<h2>Paragraph - p tag</h2>⭔<p>⭔The "p" tag is used for paragraphs; we put paragraphs inside it.⭔</p>⭔<p>⭔Here is another paragraph.⭔</p>⭔</body>⭔</html>""",
'4':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Link Tag</title>⭔</head>⭔<body>⭔<h1>Heading</h1>⭔<p>This is a paragraph.</p>⭔<a href="https://oyoclass.com">OYOclass</a>⭔<p>⭔<a href="https://youtube.com" target="_blank">⭔Click me to open Youtube in a new window⭔</a>⭔</p>⭔</body>⭔</html>""",
'5':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Image Tag</title>⭔</head>⭔<body>⭔<h1>HTML - image tag</h1>⭔<p>⭔<img src="https://speedcode.oyohub.com/img/html.png" />⭔</p>⭔<p>⭔<img width="80px" src="https://speedcode.oyohub.com/img/html.png" />⭔</p>⭔<p>⭔View more examples at⭔<a href="http://www.w3schools.com/html/html_images.asp">W3schools</a>⭔</p>⭔</body>⭔</html>""",
'6':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Line Break Tag</title>⭔</head>⭔<body>⭔<h1>br - Line Break Tag</h1>⭔<p>⭔We have some text on this line,⭔some more text on this line,⭔but when we preview this web page,⭔all of these text are on one line.⭔</p>⭔<p>⭔This is because the browser will ignore the text line-break in HTML code.⭔If we want to create a line-break, we need to explicitly add a line-break tag:⭔<br/>⭔Now this line will appear on another line. We can also insert⭔multiple line break tags.⭔<br/>⭔<br/>⭔This line will be shown on the next next line.⭔</p>⭔</body>⭔</html>""",
'7':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Unordered List Tag</title>⭔</head>⭔<body>⭔<h1>ul - Unordered list tag</h1>⭔<p>⭔"ul" stands for "unordered list". Inside this tag⭔we use the "li" tag, which stands for "list item".⭔</p>⭔<h2>My shopping list</h2>⭔<ul>⭔<li>Apple juice</li>⭔<li>Avocado</li>⭔<li>Summer sausage</li>⭔<li>2% fat milk</li>⭔</ul>⭔</body>⭔</html>""",
'8':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Ordered List Tag</title>⭔</head>⭔<body>⭔<h1>ol - Ordered list tag</h1>⭔<p>⭔"ol" stands for "ordered list". Within these tags⭔we use the "li" tag, which stands for "list item".⭔</p>⭔<h2>HTML learning plan</h2>⭔<ol>⭔<li>Learn commonly used tags</li>⭔<li>Use the web editor to practice</li>⭔<li>Complete web challenges and earn badges</li>⭔<li>Set up my own website</li>⭔</ol>⭔</body>⭔</html>""",
'9':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Text Decoration</title>⭔</head>⭔<body>⭔<h1>b, i, u, mark tags</h1>⭔<p>⭔Text inside the <b>b tag</b> will turn <b>bold</b>, <br/>⭔text inside the <i>i tag</i> will turn <i>italic</i>, <br/>⭔text inside the <u>u tag</u> will be <u>underlined</u>, <br/>⭔text inside the <mark>mark tag</mark> will be <mark>highlighted</mark>.⭔</p>⭔</body>⭔</html>""",
'10':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Audio Tag</title>⭔</head>⭔<body>⭔<h1>audio - Play some sound</h1>⭔<p>⭔The audio tag adds sound, such as music or other audio streams.⭔</p>⭔<p>⭔Click the play button to listen to the following audio: <br/>⭔<audio controls>⭔<source src="http://www.soundjay.com/ambient/spring-weather-1.mp3" type="audio/mpeg">⭔</audio>⭔</p>⭔<p>⭔You can autoplay a sound file when the page is loaded.⭔Check the autoplay attribute at⭔<a href="http://www.w3schools.com/tags/tag_audio.asp" target="_blank">W3schools</a>⭔</p>⭔</body>⭔</html>""",
'11':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Embed Scratch Games</title>⭔</head>⭔<body>⭔<h1>iframe tag - embed resources from other websites</h1>⭔<p>⭔To embed a Scratch game, make sure you have shared your project first.⭔Go to the project page, click on Embed, copy the code in the textbox,⭔then paste into your editor.⭔</p>⭔<p>⭔Your code will look something like below:⭔</p>⭔<iframe allowtransparency="true" width="485" height="402"⭔src="//scratch.mit.edu/projects/embed/117479569/⭔autostart=false"⭔frameborder="0" allowfullscreen></iframe>⭔</body>⭔</html>""",
'12':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Embed Videos</title>⭔</head>⭔<body>⭔<h1>iframe tag - Embed resources from other websites</h1>⭔<p>⭔To embed a video from YouTube, go to the video page, click on Share -> Embed,⭔copy the code in the textbox, then paste into your editor.⭔</p>⭔<iframe width="530" height="315" src="https://www.youtube.com/embed/Pcpha8fwZFw"⭔frameborder="0" allowfullscreen></iframe>⭔<iframe src="https://player.vimeo.com/video/94502406" width="530" height="360"⭔frameborder="0" allowfullscreen></iframe>⭔</body>⭔</html>""",
'13':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>How to Add CSS</title>⭔<link rel="stylesheet" type="text/css" href="style.css">⭔<style>⭔h1 {color: red}⭔</style>⭔</head>⭔<body>⭔<h1>CSS</h1>⭔<p>⭔CSS stands for "Cascading Style Sheets".⭔It is a language that describes the style of an HTML document.⭔</p>⭔<p style=""></p>⭔</body>⭔</html>""",
'14':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>CSS in style tag</title>⭔<style>⭔body {⭔background-color: green;⭔}⭔h1 {⭔color: pink;⭔}⭔p {⭔color: white;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>CSS in style tag</h1>⭔<p>Text inside the p tag becomes white because of the defined CSS above.</p>⭔</body>⭔</html>""",
'15':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>More CSS in style Tag</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔p {⭔color: blue;⭔font-weight: bold;⭔font-size: 18px;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>More CSS in style tag</h1>⭔<p>Text inside this p tag will turn blue, bold and be 18px large.</p>⭔</body>⭔</html>""",
'16':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Overriding CSS Styles</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔h1 {⭔color: #2a90b8;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>Heading</h1>⭔<p>⭔#ddd, #555 and #2a90b8 defined above are all color codes.⭔Want to find a specific color code⭔ Learn more at:⭔<a href="http://www.w3schools.com/colors/colors_picker.asp" target="_blank">⭔HTML Color Picker⭔</a>⭔</p>⭔</body>⭔</html>""",
'17':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Pseudo Classes</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔h1 {⭔color: #2a90b8;⭔}⭔a:link, a:visited {⭔color: #393;⭔}⭔a:hover, a:active {⭔color: #fff;⭔background-color: #393;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>Pseudo Classes</h1>⭔<p>This is a paragraph</p>⭔<a href="https://oyoclass.com/" target="_blank">OYOclass</a>⭔</body>⭔</html>""",
'18':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Pseudo Elements</title>⭔<style>⭔body {⭔background-color: #ddd;⭔}⭔h1::before {⭔content: url(https://speedcode.oyohub.com/img/smiley.png);⭔}⭔p::first-letter {⭔font-size: 30px;⭔}⭔p::first-line {⭔color: #393;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>Heading</h1>⭔<p>⭔The first line of this paragraph will turn green⭔according to the CSS defined above. The other lines will remain⭔black, which is the default font color.⭔</p>⭔<p>⭔Check more pseudo elements properties at:⭔<a href="http://www.w3schools.com/css/css_pseudo_elements.asp" target="_blank">⭔W3schools⭔</a>⭔</p>⭔</body>⭔</html>""",
'19':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Border, Margin and Padding</title>⭔<style>⭔body {⭔background: #eee;⭔color: #555;⭔}⭔h1 {⭔color: #2a90b8;⭔}⭔img {⭔border: 5px solid #333;⭔margin: 15px;⭔padding: 25px;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>Border, Margin and Padding</h1>⭔<p>⭔Check out my bordered image:⭔<br/>⭔<img width="150px" src="https://speedcode.oyohub.com/img/html.png" />⭔</p>⭔</body>⭔</html>""",
'20':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>CSS Reference</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔h1 {⭔color: #2a90b8;⭔text-transform: uppercase;⭔}⭔img {⭔border: 5px solid #333;⭔border-radius: 10px;⭔margin: 15px;⭔padding: 25px;⭔background-color: #efefef;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>CSS Reference</h1>⭔<p>⭔You now know a few CSS properties. Want to know more⭔⭔Check the CSS reference at:⭔<a href="http://www.w3schools.com/cssref/default.asp" target="_blank">⭔W3schools⭔</a>⭔</p>⭔<p>⭔<img width="150px" src="https://speedcode.oyohub.com/img/html.png" />⭔</p>⭔</body>⭔</html>""",
'21':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Box Model</title>⭔<style>⭔body {⭔background-color: #ddd;⭔}⭔p {⭔color: #fff;⭔background-color: #828282;⭔text-align: center;⭔padding: 10px;⭔border: 5px dashed #f90;⭔margin: 15px;⭔}⭔h1 {⭔color: #ffff98;⭔background-color: #828282;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>Heading</h1>⭔<p>Paragraph</p>⭔<p>⭔Check the image below for an explanation of the box model:⭔<br/><br/>⭔<img width="400px" src="https://speedcode.oyohub.com/img/boxmodel.png" />⭔</p>⭔</body>⭔</html>""",
'22':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Block and Inline</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔p {⭔color: #fff;⭔background-color: #828282;⭔}⭔h1 {⭔color: #ffff98;⭔background-color: #828282;⭔}⭔span {⭔background: #cf9;⭔}⭔a {⭔background: #ff9;⭔margin-top: 15px;⭔display: block;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>Heading</h1>⭔<p>Paragraph</p>⭔<span>Span1</span>⭔<span>Span2</span>⭔<a href="https://oyoclass.com/" target="_blank">OYOclass</a>⭔</body>⭔</html>""",
'23':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Float</title>⭔<style>⭔p {⭔width: 300px;⭔}⭔img {⭔padding: 5px;⭔margin: 5px 10px;⭔border: 2px solid black;⭔float: left;⭔}⭔</style>⭔</head>⭔<body>⭔<img src="https://speedcode.oyohub.com/img/html.png" width="100px">⭔<p>⭔This is a paragraph. All of the text will flow around⭔the image since it has a float property. It will continue⭔to flow around the image until text starts to spill onto⭔the next line. Text wraps around the image with the float⭔property in this example.⭔</p>⭔</body>⭔</html>""",
'24':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Div Tag</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔div {⭔margin-top: 5px;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>div - Division tag</h1>⭔<div style="background-color: #ffe7a3;">⭔This is a div. Div elements are blocks by default.⭔</div>⭔<div style="background-color: #d0ffa3;">⭔You can tell they are block elements because a second div is forced onto the next line.⭔</div>⭔<div style="background-color: #a3eaff;">⭔Also, the background colors identify the scope of each div element.⭔</div>⭔</body>⭔</html>""",
'25':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Nested Div</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔div {⭔padding: 15px;⭔}⭔</style>⭔</head>⭔<body>⭔<div style="background-color: #ffe7a3;">⭔<div style="background-color: #d0ffa3;">⭔<div style="background-color: #a3eaff;">⭔Divs can be nested inside of each other.⭔</div>⭔</div>⭔</div>⭔</body>⭔</html>""",
'26':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Rows</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔div {⭔margin-top: 5px;⭔}⭔</style>⭔</head>⭔<body>⭔<div>⭔<div style="background-color: #ffe7a3; padding: 15px;">⭔This is row 1.⭔</div>⭔<div style="background-color: #d0ffa3; padding: 15px;">⭔This is row 2.⭔</div>⭔<div style="background-color: #a3eaff; padding: 15px;">⭔This is row 3.⭔</div>⭔</div>⭔</body>⭔</html>""",
'27':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Columns</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔div {⭔margin-top: 5px;⭔}⭔</style>⭔</head>⭔<body>⭔<div>⭔<div style="background-color:#ffe7a3; padding:15px; width:25%; display:inline-block;">⭔This is column 1.⭔</div>⭔<div style="background-color:#d0ffa3; padding:15px; width:25%; display:inline-block;">⭔This is column 2.⭔</div>⭔<div style="background-color:#a3eaff; padding:15px; width:25%; display:inline-block;">⭔This is column 3.⭔</div>⭔</div>⭔</body>⭔</html>""",
'28':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Rows and Columns</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔div {⭔margin-top: 5px;⭔}⭔</style>⭔</head>⭔<body>⭔<div>⭔<div>⭔<div style="background-color: #ffe7a3; padding: 15px; width: 25%; display: inline-block;">⭔This is row 1 column 1.⭔</div>⭔<div style="background-color: #d0ffa3; padding: 15px; width: 25%; display: inline-block;">⭔This is row 1 column 2.⭔</div>⭔<div style="background-color: #a3eaff; padding: 15px; width: 25%; display: inline-block;">⭔This is row 1 column 3.⭔</div>⭔</div>⭔<div style="background-color: #ffe7a3; padding: 15px;">⭔This is row 2 column 1.⭔</div>⭔<div>⭔<div style="background-color: #d0ffa3; padding: 15px; width: 40%; display: inline-block;">⭔This is row 3 column 1.⭔</div>⭔<div style="background-color: #a3eaff; padding: 15px; width: 40%; display: inline-block;">⭔This is row 3 column 2.⭔</div>⭔</div>⭔</div>⭔</body>⭔</html>""",
'29':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>CSS with class</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔div {⭔margin-top: 5px;⭔}⭔.yellow {⭔background-color: #ffe7a3;⭔}⭔</style>⭔</head>⭔<body>⭔<div class="yellow">⭔This div has a yellow background.⭔</div>⭔<div class="yellow">⭔This too!⭔</div>⭔</body>⭔</html>""",
'30':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>CSS with ID</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔#container {⭔background-color: #fff;⭔padding: 5px;⭔width: 520px;⭔}⭔.green {⭔background-color: #d0ffa3;⭔padding: 15px;⭔}⭔</style>⭔</head>⭔<body>⭔<div id="container">⭔<div class="green">⭔This div is inside a container div!⭔</div>⭔<div class="green">⭔This div is also inside the container div!⭔</div>⭔</div>⭔</body>⭔</html>""",
'31':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Naming Scheme</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔div {⭔width: 500px;⭔padding: 15px;⭔margin-bottom: 15px;⭔}⭔.warning {⭔background-color: #ffabab;⭔}⭔.success {⭔background-color: #d0ffa3;⭔}⭔.info {⭔background-color: #a3eaff;⭔}⭔</style>⭔</head>⭔<body>⭔<div class="info">⭔You can assign classes and IDs arbitrary names like "abc" or "ttt".⭔However, it is important for you to have good naming schemes.⭔</div>⭔<div class="warning">⭔This div has a class named "warning", you intuitively know it contains warning information.⭔For example, "Are you sure you want to delete this item⭔"⭔</div>⭔<div class="success">⭔A div with a "success" class contains information which tells users they did something successfully.⭔</div>⭔<div class="info">⭔Good names help you code better! Instead of constantly referencing, you can just remember simple names.⭔Names like "warning" and "success" are better than random names like "a" and "b".⭔</div>⭔</body>⭔</html>""",
'32':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Nested Selector</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #999;⭔}⭔.container {⭔background: #FFF;⭔padding: 10px;⭔width: 510px;⭔}⭔.info p {⭔color: #20a3bd;⭔}⭔.info span {⭔font-weight: bold;⭔}⭔</style>⭔</head>⭔<body>⭔<div class="container">⭔<div class="info">⭔<p>Text in here are blue!</p>⭔<p>⭔<span>And this is bold!</span>⭔</p>⭔</div>⭔<p>But text in here are gray!</p>⭔</div>⭔</body>⭔</html>""",
'33':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Grouping Classes</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔.info p, span {⭔color: #2f6fd6;⭔}⭔</style>⭔</head>⭔<body>⭔<div class="container">⭔<div class="info">⭔<p>This paragraph is blue!</p>⭔<span>This span element is also blue!</span>⭔</div>⭔<p>But this paragraph is not blue.</p>⭔<span>This span is blue!</span>⭔</div>⭔</body>⭔</html>""",
'34':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Applying Multiple Classes</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔.colored {⭔color: #2f6fd6;⭔}⭔.bolded {⭔font-weight: bold;⭔}⭔</style>⭔</head>⭔<body>⭔<div class="container">⭔<div class="colored bolded">⭔<p>This paragraph is both blue and bold!</p>⭔</div>⭔</div>⭔</body>⭔</html>""",
'35':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Row Class</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔div {⭔margin-top: 5px;⭔}⭔.container div {⭔padding: 15px;⭔}⭔.yellow {⭔background-color: #ffe7a3;⭔}⭔.green {⭔background-color: #d0ffa3;⭔}⭔.blue {⭔background-color: #a3eaff;⭔}⭔</style>⭔</head>⭔<body>⭔<div class="container">⭔<div class="yellow">⭔This is row 1.⭔</div>⭔<div class="green">⭔This is row 2.⭔</div>⭔<div class="blue">⭔This is row 3.⭔</div>⭔</div>⭔</body>⭔</html>""",
'36':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Column Class</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔div {⭔margin-top: 5px;⭔}⭔.container div {⭔padding: 15px;⭔width: 25%;⭔display: inline-block;⭔}⭔.yellow {⭔background-color: #ffe7a3;⭔}⭔.green {⭔background-color: #d0ffa3;⭔}⭔.blue {⭔background-color: #a3eaff;⭔}⭔</style>⭔</head>⭔<body>⭔<div class="container">⭔<div class="yellow">⭔This is column 1.⭔</div>⭔<div class="green">⭔This is column 2.⭔</div>⭔<div class="blue">⭔This is column 3.⭔</div>⭔</div>⭔</body>⭔</html>""",
'37':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Row and Column Classes</title>⭔<style>⭔body {⭔background-color: #ddd;⭔color: #555;⭔}⭔div {⭔margin-top: 5px;⭔}⭔.cell {⭔padding: 15px;⭔}⭔.yellow {⭔background-color: #ffe7a3;⭔}⭔.green {⭔background-color: #d0ffa3;⭔}⭔.blue {⭔background-color: #a3eaff;⭔}⭔.column {⭔display: inline-block;⭔}⭔.column3 {⭔width: 25%;⭔}⭔.column2 {⭔width: 40%;⭔}⭔</style>⭔</head>⭔<body>⭔<div class="container">⭔<div>⭔<div class="cell yellow column column3">⭔This is row 1 column 1.⭔</div>⭔<div class="cell green column column3">⭔This is row 1 column 2.⭔</div>⭔<div class="cell blue column column3">⭔This is row 1 column 3.⭔</div>⭔</div>⭔<div class="cell yellow">⭔This is row 2 column 1.⭔</div>⭔<div>⭔<div class="cell green column column2">⭔This is row 3 column 1.⭔</div>⭔<div class="cell blue column column2">⭔This is row 3 column 2.⭔</div>⭔</div>⭔</div>⭔</body>⭔</html>""",
'38':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Navigation Bar</title>⭔<style>⭔body {⭔margin: 0;⭔font-family: Arial, sans-serif;⭔}⭔div.horizontal ul {⭔background-color: #000000;⭔list-style-type: none;⭔margin: 0;⭔padding: 0;⭔}⭔div.horizontal li {⭔float: left;⭔}⭔div.horizontal a {⭔display: block;⭔}⭔div.horizontal a:link, div.horizontal a:visited {⭔color: #FFFFFF;⭔background-color: #000000;⭔text-align: center;⭔padding: 10px 25px;⭔text-decoration: none;⭔}⭔div.horizontal a:hover, div.horizontal a:active {⭔background-color: #2baeff;⭔}⭔</style>⭔</head>⭔<body>⭔<div class="horizontal">⭔<ul>⭔<li><a href="#">Home</a></li>⭔<li><a href="#">About Me</a></li>⭔<li><a href="#">Projects</a></li>⭔</ul>⭔</div>⭔</body>⭔</html>""",
'39':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Portfolio Page</title>⭔<style>⭔h1 {⭔text-transform: capitalize;⭔}⭔h2 {⭔font-size: 20px;⭔color: #006;⭔padding-left: 1em;⭔background: url(https://speedcode.oyohub.com/img/heart.png) no-repeat;⭔}⭔#aboutme {⭔list-style-type: none;⭔margin: 0;⭔padding-left: 10px;⭔}⭔#aboutme >li::before {⭔content: "- ";⭔}⭔#aboutme b {⭔color: #666;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>Welcome to my website!</h1>⭔<h2>About Me</h2>⭔<div>⭔<ul id="aboutme">⭔<li><b>Name:</b> Steve</li>⭔<li><b>Origin:</b> Minecraft</li>⭔<li><b>Occupation:</b> Miner, builder, alchemist, hunter</li>⭔<li><b>Hobbies:</b> building, exploring, mining</li>⭔</ul>⭔</div>⭔<h2>My Scratch Project</h2>⭔<div>⭔<iframe allowtransparency="true" width="485" height="402"⭔src="//scratch.mit.edu/projects/embed/11346139/⭔autostart=false"⭔frameborder="0" allowfullscreen></iframe>⭔</div>⭔<h2>My PythonMini Project</h2>⭔<div>⭔<iframe width="90%" height="600px"⭔src="https://pythonmini.oyohub.com/file/558edbf0f3c51240cd3c925e"⭔frameborder="0"></iframe>⭔</div>⭔</body>⭔</html>""",
'40':"""<!DOCTYPE html>⭔<html>⭔<head>⭔<title>Badge Collection</title>⭔<style>⭔h1 {⭔width: 520px;⭔text-align: center;⭔font-size: 30px;⭔}⭔#badge_list {⭔list-style-type: none;⭔margin: 0;⭔padding: 0;⭔width: 520px;⭔font-family: "Comic Sans MS", cursive, sans-serif;⭔}⭔#badge_list li {⭔float: left;⭔text-align: center;⭔width: 240px;⭔margin-right: 10px;⭔margin-bottom: 20px;⭔}⭔.badge_image {⭔max-width: 166px;⭔}⭔.badge_name {⭔font-size: 18px;⭔color: #069;⭔font-weight: bold;⭔border-top: 1px dotted #CCC;⭔padding: 10px;⭔}⭔.card {⭔border: 1px solid #F1F1F1;⭔border-radius: .5em;⭔box-shadow: 0px 4px 8px 0px #CCC;⭔}⭔</style>⭔</head>⭔<body>⭔<h1>My Badge Collections</h1>⭔<div>⭔<ul id="badge_list">⭔<li class="card">⭔<div>⭔<img class="badge_image" src="https://speedcode.oyohub.com/img/maze-star1.png"/>⭔</div>⭔<div class="badge_name">⭔1-Star Maze Runner⭔</div>⭔</li>⭔<li class="card">⭔<div>⭔<img class="badge_image" src="https://speedcode.oyohub.com/img/python-10wpm.png"/>⭔</div>⭔<div class="badge_name">⭔Python 10 WPM⭔</div>⭔</li>⭔</ul>⭔</div>⭔</body>⭔</html>"""
},
'c++': {
'1': """#include <iostream>⭔int main() {⭔std::cout << "Hello World!" << std::endl;⭔std::cout << 123 << std::endl;⭔std::cout << "Change to your own string here" << std::endl;⭔return 0;⭔}""",
'2':"""#include <iostream>⭔int main() {⭔std::cout << "Comments in C++" << std::endl;⭔std::cout << "Use // to comment single line" << std::endl;⭔std::cout << "Use /* ... */ to comment multi lines" << std::endl;⭔return 0;⭔}""",
'3':"""#include <iostream>⭔int main() {⭔std::cout << 123 + 456 << std::endl;⭔std::cout << 123 * 456 << std::endl;⭔std::cout << 144 / 12 << std::endl;⭔std::cout << 12 * 3 + 4 << std::endl;⭔std::cout << 12 * (3 + 4) << std::endl;⭔return 0;⭔}""",
'4':"""#include <iostream>⭔int main() {⭔int v = 5;⭔std::cout << v << std::endl;⭔v = 6;⭔std::cout << v << std::endl;⭔v = v + 1;⭔std::cout << v << std::endl;⭔int i = 2;⭔int sum = v + i;⭔std::cout << sum << std::endl;⭔return 0;⭔}""",
'5':"""#include <iostream>⭔int main() {⭔double num1 = 0.05;⭔double num2 = 0.6;⭔double result = num1 + num2;⭔std::cout << result << std::endl;⭔result = num1 * num2;⭔std::cout << result << std::endl;⭔int i = 3;⭔result = i + num1 + num2;⭔std::cout << result << std::endl;⭔return 0;⭔}""",
'6':"""#include <iostream>⭔int main() {⭔char c1 = 'n';⭔char c2 = 'y';⭔std::cout << c1 << c2 << std::endl;⭔bool b = true;⭔std::cout << b << std::endl;⭔b = 3 > 2;⭔std::cout << b << std::endl;⭔b = 2.3 < 1.4;⭔std::cout << b << std::endl;⭔return 0;⭔}""",
'7':"""#include <iostream>⭔const double PI = 3.14159;⭔int main() {⭔std::cout << "PI's value is " << PI << std::endl;⭔double radius = 2.5;⭔std::cout << "Circumference of a circle with radius "⭔<< radius << " is " << 2 * PI * radius << std::endl;⭔std::cout << "Area of a circle with radius "⭔<< radius << " is " << PI * radius * radius << std::endl;⭔const int secondsInOneMinute = 60;⭔const int minutesInOneHour = 60;⭔const int hoursInOneDay = 24;⭔std::cout << "Seconds in one day: "⭔<< secondsInOneMinute * minutesInOneHour * hoursInOneDay⭔<< std::endl;⭔return 0;⭔}""",
'8':"""#include <iostream>⭔#include <string>⭔int main() {⭔std::string intro = "My name is Nick";⭔std::cout << intro << std::endl;⭔std::string food = "I love pizza!";⭔std::cout << food << std::endl;⭔std::string joinedString = intro + ", " + food;⭔std::cout << joinedString << std::endl;⭔std::cout << "The above string's length is: "⭔<< joinedString.length() << std::endl;⭔return 0;⭔}""",
'9':"""#include <iostream>⭔#include <string>⭔int main() {⭔std::string hello = "Hello C++";⭔int pos = hello.find("ello");⭔std::cout << "ello is at position " << pos << std::endl;⭔pos = hello.find("C++");⭔std::cout << "C++ is at position " << pos << std::endl;⭔std::string sub = hello.substr(1, 4);⭔std::cout << "Substring is: " << sub << std::endl;⭔hello.insert(1, "ee");⭔std::cout << hello << std::endl;⭔hello.erase(1, 2);⭔std::cout << hello << std::endl;⭔return 0;⭔}""",
'10':"""#include <iostream>⭔#include <string>⭔using namespace std;⭔int main() {⭔cout << "Did you notice now we don't need to use std:: ⭔" << endl;⭔cout << "The magic is 'using namespace std;'" << endl;⭔cout << "Because 'cout' belongs to namespace 'std', "⭔<< "we need to use std::cout before to tell the compiler "⭔<< "to find cout from the namespace std" << endl;⭔cout << "Now we explicitly write 'using namespace std' "⭔<< "in the beginning, so we don't need the std:: prefix anymore"⭔<< endl;⭔cout << "This works for using string too!" << endl;⭔string sayHello = "Hello World";⭔cout << "String is: " << sayHello << endl;⭔return 0;⭔}""",
'11':"""#include <iostream>⭔using namespace std;⭔int main() {⭔int x = 5;⭔if (x > 0) {⭔cout << "X is a positive number" << endl;⭔}⭔if (x < 0) {⭔cout << "X is a negative number" << endl;⭔}⭔if (x == 0) {⭔cout << "X is zero" << endl;⭔}⭔return 0;⭔}""",
'12':"""#include <iostream>⭔#include <string>⭔using namespace std;⭔int main() {⭔string weather = "Sunny";⭔if (weather == "Sunny") {⭔cout << "Let's go on a picnic!" << endl;⭔} else if (weather == "Rainy") {⭔cout << "Let's play game at home" << endl;⭔} else {⭔cout << "We will see ..." << endl;⭔}⭔return 0;⭔}""",
'13':"""#include <iostream>⭔#include <cstdlib>⭔#include <ctime>⭔using namespace std;⭔int main() {⭔cout << "I am going to throw a dice" << endl;⭔srand(time(NULL));⭔int result = rand() % 6 + 1;⭔switch (result) {⭔case 1:⭔cout << "I get 1" << endl;⭔break;⭔case 2:⭔cout << "I get 2" << endl;⭔break;⭔case 3:⭔cout << "I get 3" << endl;⭔break;⭔case 4:⭔cout << "I get 4" << endl;⭔break;⭔case 5:⭔cout << "I get 5" << endl;⭔break;⭔case 6:⭔cout << "I get 6" << endl;⭔break;⭔default:⭔cout << "Impossible to get " << result << endl;⭔break;⭔}⭔return 0;⭔}""",
'14':"""#include <iostream>⭔using namespace std;⭔int main() {⭔int i = 10;⭔while (i > 0) {⭔cout << i << " ";⭔i = i - 1;⭔}⭔i = 10;⭔while (i > 0) {⭔cout << "I love pizza!" << endl;⭔i = i - 1;⭔}⭔i = 1;⭔do {⭔cout << "i = " << i << endl;⭔i = i - 1;⭔} while (i > 2);⭔return 0;⭔}""",
'15':"""#include <iostream>⭔#include <string>⭔using namespace std;⭔int main() {⭔for (int i = 0; i < 10; i = i + 1) {⭔cout << i << " ";⭔}⭔cout << endl;⭔for (int n = 0, i = 10; n != i; ++n, --i) {⭔cout << "n = " << n << " i = " << i << endl;⭔}⭔string s = "Hello!";⭔for (char c : s) {⭔cout << "[" << c << "] ";⭔}⭔cout << endl;⭔for (auto c : s) {⭔cout << "[" << c << "] ";⭔}⭔return 0;⭔}""",
'16':"""#include <iostream>⭔#include <string>⭔using namespace std;⭔int main() {⭔for (int i = 5; i > 0; i = i - 1) {⭔if (i == 2) {⭔cout << "Countdown aborted!";⭔break;⭔}⭔cout << i << " ";⭔}⭔cout << endl;⭔string s = "Hello world!";⭔for (auto c : s) {⭔if (c == 'd') {⭔cout << "Found 'd'!" << endl;⭔break;⭔}⭔}⭔for (int i = 5; i > 0; i = i - 1) {⭔if (i == 2) {⭔cout << "[skipped] ";⭔continue;⭔}⭔cout << i << " ";⭔}⭔return 0;⭔}""",
'17':"""#include <iostream>⭔using namespace std;⭔void countdown(int n) {⭔for (int i = n; i > 0; i = i - 1) {⭔cout << i << " ";⭔}⭔cout << endl;⭔}⭔int main() {⭔for (int i = 5; i > 0; i = i - 1) {⭔cout << i << " ";⭔}⭔cout << endl;⭔for (int i = 6; i > 0; i = i - 1) {⭔cout << i << " ";⭔}⭔cout << endl;⭔cout << "Using countdown function:" << endl;⭔countdown(5);⭔countdown(10);⭔countdown(16);⭔countdown(20);⭔return 0;⭔}""",
'18':"""#include <iostream>⭔using namespace std;⭔const double PI = 3.14159;⭔double circumference(double radius) {⭔double cir = 2 * PI * radius;⭔return cir;⭔}⭔double area(double radius) {⭔double a = PI * radius * radius;⭔return a;⭔}⭔int main() {⭔double radius = 1.5;⭔cout << "A circle with radius " << radius << endl;⭔cout << "- Its circumference is " << circumference(radius) << endl;⭔cout << "- Its area is " << area(radius) << endl;⭔cout << endl;⭔radius = 12.4;⭔cout << "A circle with radius " << radius << endl;⭔cout << "- Its circumference is " << circumference(radius) << endl;⭔cout << "- Its area is " << area(radius) << endl;⭔return 0;⭔}""",
'19':"""#include <iostream>⭔#include <string>⭔using namespace std;⭔int add(int a, int b) {⭔return a + b;⭔}⭔double add(double a, double b) {⭔return a + b;⭔}⭔double add(double a, double b, double c) {⭔return a + b + c;⭔}⭔string add(string a, string b) {⭔return a + " " + b;⭔}⭔int main() {⭔cout << add(1, 2) << endl;⭔cout << add(1.4, 36.2) << endl;⭔cout << add(1.2, 3.4, 1.414) << endl;⭔cout << add("Hello", "World") << endl;⭔return 0;⭔}""",
'20':"""#include <iostream>⭔#include <string>⭔using namespace std;⭔template <typename T>⭔T add(T a, T b) {⭔T result;⭔result = a + b;⭔return result;⭔}⭔int main() {⭔int x1 = add<int>(10, 20);⭔cout << x1 << endl;⭔double x2 = add<double>(1.2, 2.3);⭔cout << x2 << endl;⭔string x3 = add<string>("Hello ", "World");⭔cout << x3 << endl;⭔return 0;⭔}""",
'21':"""#include <iostream>⭔using namespace std;⭔void countdown(int num) {⭔cout << num << " ";⭔if (num > 0) {⭔countdown(num-1);⭔}⭔}⭔int fibonacci(int num) {⭔if (num == 0) {⭔return 0;⭔}⭔if (num == 1) {⭔return 1;⭔}⭔return fibonacci(num-2) + fibonacci(num-1);⭔}⭔int main() {⭔cout << "Countdown:" << endl;⭔countdown(10);⭔cout << endl;⭔cout << "Fibonacci:" << endl;⭔cout << "7th number of Fibonacci: " << fibonacci(7) << endl;⭔return 0;⭔}""",
'22':"""#include <iostream>⭔using namespace std;⭔int main() {⭔int i = 5, j = 10;⭔int *p1 = &i;⭔int *p2 = &j;⭔cout << "i: " << i << " address: " << p1 << endl;⭔cout << "j: " << j << " address: " << p2 << endl;⭔cout << "*p1: " << *p1 << endl;⭔*p1 = 20;⭔cout << "Now *p1 is: " << *p1 << " and i is: " << i << endl;⭔int arr[] = {10, 20, 30};⭔int length = sizeof(arr) / sizeof(arr[0]);⭔cout << "Use [] indexing to print all numbers:" << endl;⭔for (int i = 0; i < length; i++) {⭔cout << arr[i] << " ";⭔}⭔cout << endl;⭔cout << "Use pointer to print all numbers:" << endl;⭔int *start = arr;⭔for (int i = 0; i < length; i++) {⭔cout << *(start + i) << " ";⭔}⭔cout << endl;⭔return 0;⭔}""",
'23':"""#include <iostream>⭔#include <cstdlib>⭔#include <ctime>⭔using namespace std;⭔int main() {⭔int *count = new int;⭔*count = 10;⭔cout << *count << endl;⭔srand(time(NULL));⭔int *arr = new int[*count];⭔for (int i = 0; i < *count; i++) {⭔int num = rand() % 100;⭔arr[i] = num;⭔}⭔for (int i = 0; i < *count; i++) {⭔cout << arr[i] << " ";⭔}⭔cout << endl;⭔delete count;⭔delete [] arr;⭔return 0;⭔}""",
'24':"""#include <iostream>⭔using namespace std;⭔const double PI = 3.14159;⭔class Circle {⭔public:⭔Circle(double r);⭔double circumference();⭔double area();⭔private:⭔double radius;⭔};⭔Circle::Circle(double r) {⭔this->radius = r;⭔}⭔double Circle::circumference() {⭔return 2 * PI * this->radius;⭔}⭔double Circle::area() {⭔return PI * this->radius * this->radius;⭔}⭔int main() {⭔Circle c1(1.2);⭔cout << "Circle1 (radius 1.2) circumference is: " << c1.circumference()⭔<< " area is: " << c1.area() << endl;⭔Circle c2(2.5);⭔cout << "Circle2 (radius 2.5) circumference is: " << c2.circumference()⭔<< " area is: " << c2.area() << endl;⭔return 0;⭔}""",
'25':"""#include <iostream>⭔#include <string>⭔using namespace std;⭔class Car {⭔public:⭔Car(string _maker, string _type, double _mpg);⭔double canRunMilesWithGallon(double _gallon);⭔void desc();⭔private:⭔string maker;⭔string type;⭔double mpg;⭔};⭔Car::Car(string _maker, string _type, double _mpg) {⭔this->maker = _maker;⭔this->type = _type;⭔this->mpg = _mpg;⭔}⭔double Car::canRunMilesWithGallon(double _gallon) {⭔return _gallon * this->mpg;⭔}⭔void Car::desc() {⭔cout << "Maker: " << this->maker << endl;⭔cout << "Type: " << this->type << endl;⭔cout << "MPG: " << this->mpg << endl;⭔}⭔int main() {⭔int gallons = 2;⭔Car car1("Ford", "Sedan", 30);⭔cout << "car 1:" << endl;⭔car1.desc();⭔cout << "With " << gallons << " gallon gas, car1 can run "⭔<< car1.canRunMilesWithGallon(gallons) << " miles" << endl;⭔cout << endl;⭔Car car2("Audi", "SUV", 26);⭔cout << "car 2:" << endl;⭔car2.desc();⭔cout << "With " << gallons << " gallon gas, car2 can run "⭔<< car2.canRunMilesWithGallon(gallons) << " miles" << endl;⭔return 0;⭔}""",
'26':"""#include <iostream>⭔#include <string>⭔using namespace std;⭔class Person {⭔public:⭔Person(string _name, int _birthyear) {⭔this->name = _name;⭔this->birthyear = _birthyear;⭔}⭔void print() {⭔cout << "Name: " << this->name << endl;⭔cout << "Year of birth: " << this->birthyear << endl;⭔}⭔protected:⭔string name;⭔int birthyear;⭔};⭔class Student: public Person {⭔public:⭔Student(string _name, int _birthyear, string _school):⭔Person(_name, _birthyear) {⭔this->school = _school;⭔}⭔void print() {⭔Person::print();⭔cout << "School: " << this->school << endl;⭔}⭔protected:⭔string school;⭔};⭔int main() {⭔Student st("Larry", 1994, "Middle Island High School");⭔st.print();⭔return 0;⭔}""",
'27':"""#include <iostream>⭔using namespace std;⭔class Person {⭔public:⭔Person(string _name, int _birthyear) {⭔this->name = _name;⭔this->birthyear = _birthyear;⭔}⭔void print() {⭔cout << "Name: " << this->name << endl;⭔cout << "Year of birth: " << this->birthyear << endl;⭔}⭔protected:⭔string name;⭔int birthyear;⭔};⭔class Student: public Person {⭔public:⭔Student(string _name, int _birthyear, string _school):⭔Person(_name, _birthyear) {⭔this->school = _school;⭔}⭔void print() {⭔Person::print();⭔cout << "School: " << this->school << endl;⭔}⭔protected:⭔string school;⭔};⭔class CollegeStudent: public Student {⭔public:⭔CollegeStudent(string _name, int _birthyear, string _school,⭔string _major):Student(_name, _birthyear, _school) {⭔this->major = _major;⭔}⭔void print() {⭔Student::print();⭔cout << "Major: " << this->major << endl;⭔}⭔protected:⭔string major;⭔};⭔int main() {⭔CollegeStudent ss("Bob", 1990, "MIT", "Computer Science");⭔ss.print();⭔return 0;⭔}""",
'28':"""#include <iostream>⭔using namespace std;⭔class Coordinate {⭔public:⭔Coordinate(int _x, int _y):x(_x), y(_y) {}⭔Coordinate operator +(const Coordinate& other) {⭔int xx = other.x + this->x;⭔int yy = other.y + this->y;⭔return Coordinate(xx, yy);⭔}⭔void print() {⭔cout << "(" << x << ", " << y << ")" << endl;⭔}⭔protected:⭔int x;⭔int y;⭔};⭔int main() {⭔Coordinate dot1(1, 2);⭔cout << "dot1: ";⭔dot1.print();⭔Coordinate dot2(3, 4);⭔cout << "dot2: ";⭔dot2.print();⭔Coordinate dot3 = dot1 + dot2;⭔cout << "dot3: ";⭔dot3.print();⭔return 0;⭔}""",
'29':"""#include <iostream>⭔using namespace std;⭔class Square {⭔public:⭔Square():length(0) {};⭔Square(double _length):length(_length) {}⭔double area();⭔friend Square duplicate(const Square& other);⭔private:⭔double length;⭔};⭔double Square::area() {⭔return this->length * this->length;⭔}⭔Square duplicate(const Square& other) {⭔Square s;⭔s.length = other.length;⭔return s;⭔}⭔int main() {⭔Square s1(4);⭔Square s2 = duplicate(s1);⭔cout << "Square s2 's area is: " << s2.area() << endl;⭔Square s3 = duplicate(s2);⭔cout << "Square s3 's area is: " << s3.area() << endl;⭔return 0;⭔}""",
'30':"""#include <iostream>⭔#include <string>⭔using namespace std;⭔class Student {⭔friend class Printer;⭔public:⭔Student(string _id, string _name, string _school):⭔id(_id), name(_name), school(_school) {}⭔private:⭔string id;⭔string name;⭔string school;⭔};⭔class Printer {⭔public:⭔void print(Student &s) {⭔cout << "Student Information" << endl;⭔cout << "===================" << endl;⭔cout << "ID:\\t" << s.id << endl;⭔cout << "Name:\\t" << s.name << endl;⭔cout << "School:\\t" << s.school << endl;⭔}⭔};⭔int main() {⭔Student s1("108809", "Nick", "Long Island High School");⭔Student s2("109910", "Jack", "Montauk Elementary School");⭔Printer myPrinter;⭔myPrinter.print(s1);⭔cout << endl;⭔myPrinter.print(s2);⭔return 0;⭔}""",
'31':"""#include <iostream>⭔#include <string>⭔#include <vector>⭔using namespace std;⭔class Animal {⭔public:⭔Animal() {}⭔Animal(string _name):name(_name) {}⭔string getName() const {return this->name;}⭔virtual void speak() = 0;⭔protected:⭔string name;⭔};⭔class Cat:public Animal {⭔public:⭔Cat(string _name):Animal(_name) {}⭔void speak() {⭔cout << "meow meow ⭔" << endl;⭔}⭔};⭔class Dog:public Animal {⭔public:⭔Dog(string _name):Animal(_name) {}⭔void speak() {⭔cout << "woof woof ⭔" << endl;⭔}⭔};⭔int main() {⭔vector<Animal*> animals;⭔animals.push_back(new Cat("Garfield"));⭔animals.push_back(new Dog("Pluto"));⭔for (int i = 0; i < animals.size(); i++) {⭔cout << animals[i]->getName() << ": ";⭔animals[i]->speak();⭔}⭔for (int i = 0; i < animals.size(); i++) {⭔delete animals[i];⭔}⭔return 0;⭔}""",
'32':"""#include <iostream>⭔#include <string>⭔using namespace std;⭔template <typename Type1, typename Type2>⭔class Pair {⭔public:⭔Pair(Type1 t1, Type2 t2) {⭔this->first = t1;⭔this->second = t2;⭔}⭔void setFirst(Type1 t1) {⭔this->first = t1;⭔}⭔void setSecond(Type2 t2) {⭔this->second = t2;⭔}⭔Type1 getFirst() const {⭔return this->first;⭔}⭔Type2 getSecond() const {⭔return this->second;⭔}⭔private:⭔Type1 first;⭔Type2 second;⭔};⭔int main() {⭔Pair<double, double> point(2, 2.5);⭔cout << "Point coordinate: " << "(" << point.getFirst() << ", "⭔<< point.getSecond() << ")" << endl;⭔Pair<string, string> name("James", "Smith");⭔cout << "Name: " << name.getFirst() << " "⭔<< name.getSecond() << endl;⭔Pair<string, double> item("Apple Juice", 2.48);⭔cout << "Beverage: " << item.getFirst() << " $"⭔<< item.getSecond() << endl;⭔return 0;⭔}""",
'33':"""#include <iostream>⭔#include <vector>⭔#include <algorithm>⭔#include <iterator>⭔#include <ctime>⭔#include <cstdlib>⭔using namespace std;⭔int main() {⭔vector<int> numbers;⭔srand(time(NULL));⭔for (int i = 0; i < 10; i++) {⭔numbers.push_back(rand() % 100);⭔}⭔int count = numbers.size();⭔cout << "We have " << count << " numbers:" << endl;⭔for (int i = 0; i < count; i++) {⭔cout << numbers[i] << " ";⭔}⭔cout << endl;⭔cout << "1st number: " << numbers.front() << endl;⭔cout << "last number: " << numbers.back() << endl;⭔auto iter = numbers.begin();⭔numbers.insert(iter+1, 101);⭔cout << "After inserting 101:" << endl;⭔copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));⭔cout << endl;⭔numbers.erase(iter+2);⭔cout << "After removing 3rd element:" << endl;⭔copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));⭔return 0;⭔}""",
'34':"""#include <iostream>⭔#include <vector>⭔using namespace std;⭔void print_vector(vector<vector<int>>& vec) {⭔for (int i = 0; i < vec.size(); i++) {⭔for (int j = 0; j < vec[i].size(); j++) {⭔cout << vec[i][j] << " ";⭔}⭔cout << endl;⭔}⭔}⭔int main() {⭔int rows = 4, cols = 5;⭔vector<vector<int>> vec(rows, vector<int>(cols));⭔int start = 10;⭔for (int i = 0; i < vec.size(); i++) {⭔for (int j = 0; j < vec[i].size(); j++) {⭔vec[i][j] = start;⭔start = start + 1;⭔}⭔}⭔print_vector(vec);⭔vec[1][3] = 99;⭔cout << endl;⭔print_vector(vec);⭔cout << endl;⭔for (int i = 0; i < vec.size(); i++) {⭔cout << vec[i].back() << endl;⭔}⭔cout << endl;⭔for (int i = 0; i < vec.size(); i++) {⭔vec[i].push_back(100 + i);⭔}⭔print_vector(vec);⭔return 0;⭔}""",
'35':"""#include <iostream>⭔#include <list>⭔#include <ctime>⭔#include <cstdlib>⭔using namespace std;⭔void print_list(list<int>& lst) {⭔auto iter = lst.begin();⭔for (iter; iter != lst.end(); iter++) {⭔cout << *iter << " ";⭔}⭔}⭔int main() {⭔list<int> numbers;⭔srand(time(NULL));⭔for (int i = 0; i < 10; i++) {⭔numbers.push_back(rand() % 100);⭔}⭔int count = numbers.size();⭔cout << "We have " << count << " numbers:" << endl;⭔print_list(numbers);⭔cout << endl;⭔cout << "1st number: " << numbers.front() << endl;⭔cout << "last number: " << numbers.back() << endl;⭔auto iter = numbers.begin();⭔iter++;⭔iter = numbers.insert(iter, 101);⭔cout << "After inserting 101:" << endl;⭔print_list(numbers);⭔cout << endl;⭔iter++;⭔numbers.erase(iter);⭔cout << "After removing the number after 101:" << endl;⭔print_list(numbers);⭔return 0;⭔}""",
'36':"""#include <iostream>⭔#include <stack>⭔#include <queue>⭔using namespace std;⭔int main() {⭔stack<int> mystack;⭔for (int i = 0; i < 5; i++) {⭔mystack.push(i);⭔}⭔cout << "mystack has " << mystack.size()⭔<< " elements, and top element is: " << mystack.top() << endl;⭔mystack.pop();⭔cout << "Popped the last element" << endl;⭔cout << "mystack has " << mystack.size()⭔<< " elements, and top element is: " << mystack.top() << endl;⭔cout << endl;⭔queue<int> myqueue;⭔for (int i = 10; i < 15; i++) {⭔myqueue.push(i);⭔}⭔cout << "myqueue has " << myqueue.size()⭔<< " elements, and the front element is: " << myqueue.front() << endl;⭔myqueue.pop();⭔cout << "Poped the front element" << endl;⭔cout << "myqueue has " << myqueue.size()⭔<< " elements, and front element is: " << myqueue.front() << endl;⭔return 0;⭔}""",
'37':"""#include <iostream>⭔#include <map>⭔using namespace std;⭔int main() {⭔cout << "Define a map, the key is the student-name, the value is the student-score" << endl;⭔map<string, int> studentScore;⭔studentScore["Aaron"] = 87;⭔studentScore["Alice"] = 89;⭔studentScore["Bob"] = 85;⭔studentScore["Henry"] = 70;⭔studentScore["Ivy"] = 92;⭔studentScore["Jack"] = 65;⭔string name = "Henry";⭔cout << "Looking up score for " << name << endl;⭔map<string, int>::iterator iter;⭔iter = studentScore.find(name);⭔if (iter == studentScore.end()) {⭔cout << "- Can't find score for " << name;⭔} else {⭔cout << "- " << name << " got score: " << iter->second << endl;⭔}⭔name = "Kuri";⭔cout << "Looking up score for " << name << endl;⭔iter = studentScore.find(name);⭔if (iter == studentScore.end()) {⭔cout << "- Can't find score for " << name;⭔} else {⭔cout << "- " << name << " got score: " << iter->second << endl;⭔}⭔return 0;⭔}""",
'38':"""#include <iostream>⭔#include <vector>⭔#include <ctime>⭔#include <cstdlib>⭔using namespace std;⭔int main() {⭔vector<int> numbers;⭔srand(time(NULL));⭔for (int i = 0; i < 10; i++) {⭔int number = rand() % 100;⭔numbers.push_back(number);⭔}⭔for (int i = 0; i < numbers.size(); i++) {⭔cout << numbers[i] << " ";⭔}⭔cout << endl;⭔int max = 0, min = 100;⭔for (int i = 0; i < numbers.size(); i++) {⭔int number = numbers[i];⭔if (max < number) {⭔max = number;⭔}⭔if (min > number) {⭔min = number;⭔}⭔}⭔cout << "Max number is: " << max << endl;⭔cout << "Min number is: " << min << endl;⭔return 0;⭔}""",
'39':"""#include <iostream>⭔#include <vector>⭔#include <ctime>⭔#include <cstdlib>⭔using namespace std;⭔int main() {⭔vector<int> numbers;⭔srand(time(NULL));⭔for (int i = 0; i < 10; i++) {⭔int number = rand() % 100;⭔numbers.push_back(number);⭔}⭔cout << "Before sorting" << endl;⭔for (int i = 0; i < numbers.size(); i++) {⭔cout << numbers[i] << " ";⭔}⭔cout << endl;⭔for (int i = 0; i < numbers.size(); i++) {⭔int minIndex = i;⭔for (int j = i; j < numbers.size(); j++) {⭔if (numbers[minIndex] > numbers[j]) {⭔minIndex = j;⭔}⭔}⭔if (minIndex != i) {⭔int temp = numbers[minIndex];⭔numbers[minIndex] = numbers[i];⭔numbers[i] = temp;⭔}⭔}⭔cout << "After sorting" << endl;⭔for (int i = 0; i < numbers.size(); i++) {⭔cout << numbers[i] << " ";⭔}⭔return 0;⭔}""",
'40':"""#include <iostream>⭔#include <vector>⭔#include <algorithm>⭔#include <iterator>⭔#include <ctime>⭔#include <cstdlib>⭔using namespace std;⭔int main() {⭔vector<int> numbers;⭔srand(time(NULL));⭔for (int i = 0; i < 10; i++) {⭔int number = rand() % 100;⭔numbers.push_back(number);⭔}⭔cout << "Before sorting:" << endl;⭔copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));⭔bool swapped = false;⭔do {⭔swapped = false;⭔for (int i = 1; i < numbers.size(); i++) {⭔if (numbers[i-1] > numbers[i]) {⭔int temp = numbers[i];⭔numbers[i] = numbers[i-1];⭔numbers[i-1] = temp;⭔swapped = true;⭔}⭔}⭔} while (swapped);⭔cout << endl;⭔cout << "After sorting:" << endl;⭔copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));⭔return 0;⭔}"""
},
'java': {
'1':"""public class PrintStatement {⭔public static void main(String[] args) {⭔System.out.println("Hello World");⭔System.out.println("Good morning!");⭔System.out.print("The T-rex has the PIE!");⭔}⭔}""",
'2':"""public class DataTypes {⭔public static void main(String[] args) {⭔int a = 10;⭔double b = 2.33;⭔float c = 3.55f;⭔char d = 't';⭔boolean e = true;⭔System.out.println(a);⭔System.out.println(b);⭔System.out.println(c);⭔System.out.println(d);⭔System.out.println(e);⭔}⭔}""",
'3':"""public class Casting {⭔public static void main(String[] args) {⭔int a = 10;⭔double b = 2.33;⭔float c = 3.55f;⭔int d = (int)b;⭔System.out.println(d);⭔double e = (double)a;⭔System.out.println(e);⭔}⭔}""",
'4':"""public class Calculator {⭔public static void main(String[] args) {⭔int a = 10;⭔int b = 5;⭔System.out.println(a + b);⭔System.out.println(a - b);⭔System.out.println(a * b);⭔System.out.println(a / b);⭔System.out.println(a + a / b);⭔}⭔}""",
'5':"""public class IncDecDemo {⭔public static void main(String[] args) {⭔int a = 10;⭔int b = a++;⭔int c = ++a;⭔int d = a--;⭔int e = --a;⭔System.out.println(a);⭔System.out.println(b);⭔System.out.println(c);⭔System.out.println(d);⭔System.out.println(e);⭔}⭔}""",
'6':"""public class ArraysDemo {⭔public static void main(String[] args) {⭔int[] arr = new int[5];⭔arr[0] = 10;⭔arr[1] = 11;⭔arr[2] = 12;⭔arr[3] = 14;⭔arr[4] = 15;⭔System.out.println(arr[0]);⭔System.out.println(arr[1]);⭔System.out.println(arr[2]);⭔System.out.println(arr[3]);⭔System.out.println(arr[4]);⭔}⭔}""",
'7':"""public class ConditionsDemo {⭔public static void main(String[] args) {⭔int a = 3;⭔int b = 4;⭔boolean c = (a != b);⭔if (a < b) {⭔System.out.println("A is smaller!");⭔}⭔else if (a > b) {⭔System.out.println("B is smaller!");⭔}⭔else {⭔System.out.println("A and B are equal!");⭔}⭔}⭔}""",
'8':"""public class AndOr {⭔public static void main(String[] args) {⭔int a = 3;⭔int b = 4;⭔int c = 4;⭔boolean d = (a < b && a < c);⭔boolean e = (b >= c || b < a);⭔System.out.println(d);⭔System.out.println(e);⭔}⭔}""",
'9':"""public class LeapYear {⭔public static void main(String[] args) {⭔int year = 2104;⭔boolean c1 = (year % 4 == 0);⭔boolean c2 = (year % 100 != 0);⭔boolean c3 = (year % 100 == 0 && year % 400 == 0);⭔if (c1 && (c2 || c3)) {⭔System.out.println(year + " is a leap year");⭔}⭔else {⭔System.out.println(year + " is not a leap year");⭔}⭔}⭔}""",
'10':"""public class StringDemo {⭔public static void main(String[] args) {⭔String str = "I am a dinosaur.";⭔System.out.println("The string has "⭔+ str.length()⭔+ " characters.");⭔System.out.println(str.substring(3, 11));⭔System.out.print("Does '" + str⭔+ "' contain the letter d? ");⭔System.out.println(str.contains("d"));⭔System.out.print("Does '" + str + "' contain 'You are'? ");⭔System.out.println(str.contains("You are"));⭔}⭔}""",
'11':"""public class StringEquality {⭔public static void main(String[] args) {⭔String str1 = "hello";⭔String str2 = "hi";⭔String str3 = str1;⭔String str4 = new String("hello");⭔System.out.println(str1.equals(str2));⭔System.out.println(str1.equals(str3));⭔System.out.println(str1 == str4);⭔System.out.println(str1 == str3);⭔}⭔}""",
'12':"""public class ForLoopsDemo {⭔public static void main(String[] args) {⭔int[] arr = new int[10];⭔for (int i = 0; i < 10; i++) {⭔arr[i] = i*i;⭔}⭔for (int i = 9; i >= 0; i--) {⭔System.out.println(arr[i]);⭔}⭔}⭔}""",
'13':"""public class FizzBuzz {⭔public static void main(String[] args) {⭔for (int i = 1; i <= 100; i++) {⭔if (i % 3 == 0) {⭔System.out.print("fizz");⭔}⭔if (i % 5 == 0) {⭔System.out.print("buzz");⭔}⭔if (!(i % 3 == 0 || i % 5 == 0)) {⭔System.out.print(i);⭔}⭔System.out.println();⭔}⭔}⭔}""",
'14':"""public class WhileLoopsDemo {⭔public static void main(String[] args) {⭔int i = 0;⭔while (i < 10) {⭔System.out.println(i);⭔i++;⭔}⭔System.out.println("----");⭔while (i <= 100) {⭔System.out.println(i);⭔i += 10;⭔}⭔}⭔}""",
'15':"""public class ForEachLoopsDemo {⭔public static void main(String[] args) {⭔int[] numbers = new int[10];⭔for (int i = 0; i < 10; i++) {⭔numbers[i] = i + 1;⭔}⭔for (int num : numbers) {⭔System.out.println(num * (num + 2));⭔}⭔}⭔}""",
'16':"""public class Palindrome {⭔public static void main(String[] args) {⭔String s = "racecar";⭔int low = 0;⭔int high = s.length() - 1;⭔boolean isPalindrome = true;⭔while (high > low) {⭔if (s.charAt(low) != s.charAt(high)) {⭔isPalindrome = false;⭔break;⭔}⭔low++;⭔high--;⭔}⭔if (isPalindrome) {⭔System.out.println(s + " is a palindrome.");⭔}⭔else {⭔System.out.println(s + " is not a palindrome.");⭔}⭔}⭔}""",
'17':"""public class TwoDimensionArray {⭔public static void main(String[] args) {⭔int[][] arr = new int[10][10];⭔for (int i = 0; i < arr[0].length; i++) {⭔for (int j = arr.length-1; j >= 0; j--) {⭔arr[j][i] = (i+j) % 10;⭔}⭔}⭔for (int i = 0; i < arr.length; i++) {⭔System.out.print("[ ");⭔for (int j = 0; j < arr[i].length; j++) {⭔System.out.print(arr[i][j] + " ");⭔}⭔System.out.println("]");⭔}⭔}⭔}""",
'18':"""public class MathLibrary {⭔public static void main(String[] args) {⭔int a = 1;⭔int b = 4;⭔int c = -2;⭔double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c))/(2 * a);⭔double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c))/(2 * a);⭔System.out.printf("The roots are: %.2f and %.2f", x1, x2);⭔}⭔}""",
'19':"""public class FunctionsDemo {⭔public static void main(String[] args) {⭔int a = 5;⭔int b = 10;⭔int c = add(a, b);⭔System.out.println(a + " + " + b + " = " + c);⭔}⭔public static int add(int a, int b) {⭔return a + b;⭔}⭔}""",
'20':"""public class ConversionDemo {⭔public static void main(String[] args) {⭔double fahrenheit = 74.0;⭔double celsius = 33.0;⭔System.out.println(fahrenheit⭔+ " degrees F = "⭔+ fahrenheitToCelsius(fahrenheit)⭔+ " degrees C.");⭔System.out.println(celsius⭔+ " degrees C = "⭔+ celsiusToFahrenheit(celsius)⭔+ " degrees F.");⭔}⭔public static double fahrenheitToCelsius(double fahrenheit) {⭔return (fahrenheit - 32.0) * (5.0/9.0);⭔}⭔public static double celsiusToFahrenheit(double celsius) {⭔return (celsius * (9.0/5.0)) + 32.0;⭔}⭔}""",
'21':"""public class ConversionDemo2 {⭔public static void main(String[] args) {⭔double miles = 3.5;⭔double km = 6.25;⭔System.out.println(miles + " miles = "⭔+ milesToKm(miles) + " km.");⭔System.out.println(km + " km = "⭔+ kmToMiles(km) + " miles.");⭔}⭔public static double milesToKm(double miles) {⭔return miles * 1.6;⭔}⭔public static double kmToMiles(double km) {⭔return km / 1.6;⭔}⭔}""",
'22':"""public class BinaryToDecimal {⭔public static void main(String[] args) {⭔String binary = "101101";⭔int decimal = binaryToDecimal(binary);⭔System.out.println(binary + " in binary is "⭔+ decimal + " in decimal.");⭔}⭔public static int binaryToDecimal(String bin) {⭔int pow = 0;⭔int decimal = 0;⭔int binLength = bin.length();⭔for (int i = binLength - 1; i >= 0; i--) {⭔String s = bin.substring(i, i+1);⭔int n = Integer.parseInt(s);⭔decimal += n * Math.pow(2, pow);⭔pow++;⭔}⭔return decimal;⭔}⭔}""",
'23':"""public class HexToDecimal {⭔public static void main(String[] args) {⭔String hex = "5b";⭔int decimal = hexToDec(hex);⭔System.out.println(hex + " in hexadecimal is "⭔+ decimal + " in decimal.");⭔}⭔public static int hexToDec(String hex) {⭔int pow = 0;⭔int decimal = 0;⭔for (int i = hex.length()-1; i >= 0; i--) {⭔String s = hex.substring(i, i+1);⭔int n;⭔if (s.equals("a"))⭔n = 10;⭔else if (s.equals("b"))⭔n = 11;⭔else if (s.equals("c"))⭔n = 12;⭔else if (s.equals("d"))⭔n = 13;⭔else if (s.equals("e"))⭔n = 14;⭔else if (s.equals("f"))⭔n = 15;⭔else⭔n = Integer.parseInt(s);⭔decimal += n * Math.pow(16, pow);⭔pow++;⭔}⭔return decimal;⭔}⭔}""",
'24':"""public class OctalToDecimal {⭔public static void main(String[] args) {⭔String oct = "43";⭔int decimal = octToDecimal(oct);⭔System.out.println(oct + " in octal is "⭔+ decimal + " in decimal.");⭔}⭔public static int octToDecimal(String oct) {⭔int pow = 0;⭔int decimal = 0;⭔for (int i = oct.length()-1; i >= 0; i--) {⭔String s = oct.substring(i, i+1);⭔int n = Integer.parseInt(s);⭔decimal += n * Math.pow(8, pow);⭔pow++;⭔}⭔return decimal;⭔}⭔}""",
'25':"""public class FindPrime {⭔public static void main(String[] args) {⭔int[] arr = findPrimes(50);⭔for (int i = 0; i < arr.length; i++) {⭔if (arr[i] == 0) {⭔break;⭔}⭔System.out.println(arr[i]);⭔}⭔}⭔public static int[] findPrimes(int limit) {⭔int[] primes = new int[limit/2];⭔int index = 0;⭔for (int i = 2; i <= limit; i++) {⭔boolean isPrime = true;⭔for (int j = 2; j < i; j++) {⭔if (i % j == 0) {⭔isPrime = false;⭔break;⭔}⭔}⭔if (isPrime) {⭔primes[index] = i;⭔index++;⭔}⭔}⭔return primes;⭔}⭔}""",
'26':"""public class AverageDemo {⭔public static void main(String[] args) {⭔int[] list = new int[20];⭔for (int i = 0; i < 20; i++) {⭔list[i] = (int)(Math.random() * 10) + 1;⭔System.out.print(list[i] + " ");⭔}⭔System.out.println("\\nThe average is " + findMean(list));⭔}⭔public static double findMean(int[] list) {⭔double average = 0;⭔for (int i = 0; i < list.length; i++) {⭔average += list[i];⭔}⭔average /= list.length;⭔return average;⭔}⭔}""",
'27':"""public class SelectionSort {⭔public static void main(String[] args) {⭔int[] unsortedList = {5, 3, 7, 2, 6, 9, 4};⭔System.out.println("Before sorting:");⭔for (int i = 0; i < unsortedList.length; i++) {⭔System.out.print(unsortedList[i] + " ");⭔}⭔System.out.println();⭔int[] sortedList = selectionSort(unsortedList);⭔System.out.println("After sorting:");⭔for (int i = 0; i < sortedList.length; i++) {⭔System.out.print(sortedList[i] + " ");⭔}⭔}⭔public static int[] selectionSort(int[] list) {⭔for (int i = 0; i < list.length; i++) {⭔int min = i;⭔for (int j = list.length-1; j > i; j--) {⭔if (list[j] < list[min]) {⭔min = j;⭔}⭔}⭔if (min != i) {⭔int temp = list[min];⭔list[min] = list[i];⭔list[i] = temp;⭔}⭔}⭔return list;⭔}⭔}""",
'28':"""public class BubbleSortDemo {⭔public static void main(String[] args) {⭔int[] unsortedList = {5, 3, 7, 2, 6, 9, 4};⭔System.out.println("Before sorting:");⭔for (int i = 0; i < unsortedList.length; i++) {⭔System.out.print(unsortedList[i] + " ");⭔}⭔System.out.println();⭔System.out.println("After sorting:");⭔int[] sortedList = bubbleSort(unsortedList);⭔for (int i = 0; i < sortedList.length; i++) {⭔System.out.print(sortedList[i] + " ");⭔}⭔}⭔public static int[] bubbleSort(int[] list) {⭔for (int i = list.length-2; i >= 0; i--) {⭔for (int j = list.length-1; j >= i; j--) {⭔if (list[j] < list[i]) {⭔int temp = list[j];⭔list[j] = list[i];⭔list[i] = temp;⭔}⭔}⭔}⭔return list;⭔}⭔}""",
'29':"""public class MergeSortDemo {⭔static int[] list;⭔static int[] tempList;⭔public static void main(String[] args) {⭔list = new int[]{5, 4, 7, 9, 2, 2, 1, 6, 3};⭔System.out.println("Before sorting:");⭔for (int i = 0; i < list.length; i++) {⭔System.out.print(list[i] + " ");⭔}⭔tempList = new int[list.length];⭔mergeSort(0, list.length-1);⭔System.out.println();⭔System.out.println("After sorting:");⭔for (int i = 0; i < list.length; i++) {⭔System.out.print(list[i] + " ");⭔}⭔}⭔public static void mergeSort(int low, int high) {⭔if (low < high) {⭔int mid = low + (high - low) / 2;⭔mergeSort(low, mid);⭔mergeSort(mid + 1, high);⭔merge(low, mid, high);⭔}⭔}⭔public static void merge(int low, int mid, int high) {⭔for (int i = low; i <= high; i++) {⭔tempList[i] = list[i];⭔}⭔int i = low;⭔int j = mid + 1;⭔int k = low;⭔while (i <= mid && j <= high) {⭔if (tempList[i] <= tempList[j]) {⭔list[k] = tempList[i];⭔i++;⭔} else {⭔list[k] = tempList[j];⭔j++;⭔}⭔k++;⭔}⭔while (i <= mid) {⭔list[k] = tempList[i];⭔k++;⭔i++;⭔}⭔}⭔}""",
'30':"""import java.util.ArrayList;⭔public class FindMaxMin {⭔public static void main(String[] args) {⭔ArrayList<Integer> list = new ArrayList<Integer>();⭔for (int i = 0; i < 10; i++) {⭔int num = (int)(Math.random() * 100) + 1;⭔list.add(num);⭔System.out.print(num + " ");⭔}⭔System.out.println();⭔System.out.println("Maximum number: " + findMax(list));⭔System.out.println("Minimum number: " + findMin(list));⭔}⭔public static int findMax(ArrayList<Integer> list) {⭔int maxIndex = 0;⭔for (int i = 1; i < list.size(); i++) {⭔if (list.get(i) < list.get(maxIndex)) {⭔maxIndex = i;⭔}⭔}⭔return list.get(maxIndex);⭔}⭔public static int findMin(ArrayList<Integer> list) {⭔int minIndex = 0;⭔for (int i = 1; i < list.size(); i++) {⭔if (list.get(i) > list.get(minIndex)) {⭔minIndex = i;⭔}⭔}⭔return list.get(minIndex);⭔}⭔}""",
'31':"""public class BinarySearchDemo {⭔public static void main(String[] args) {⭔int[] list = new int[]{12, 17, 20, 24, 33, 45, 56, 77, 82, 94};⭔int index = -1;⭔index = binarySearch(list, 33);⭔if (index != -1) {⭔System.out.println("33 is found, its index is: " + index);⭔}⭔else {⭔System.out.println("33 is not found in this list.");⭔}⭔index = binarySearch(list, 17);⭔if (index != -1) {⭔System.out.println("17 is found, its index is: " + index);⭔}⭔else {⭔System.out.println("17 is not found in this list.");⭔}⭔index = binarySearch(list, 46);⭔if (index != -1) {⭔System.out.println("46 is found, its index is: " + index);⭔}⭔else {⭔System.out.println("46 is not found in this list.");⭔}⭔}⭔public static int binarySearch(int[] list, int key) {⭔int indexOfKey = -1;⭔int low = 0;⭔int high = list.length - 1;⭔int mid = low + (high - low) / 2;⭔while (high > low) {⭔mid = low + (high-low)/2;⭔if (key == list[mid]) {⭔indexOfKey = mid;⭔break;⭔}⭔else if (key > list[mid]) {⭔low = mid + 1;⭔}⭔else if (key < list[mid]) {⭔high = mid - 1;⭔}⭔}⭔return indexOfKey;⭔}⭔}""",
'32':"""public class RecursionFibonacci {⭔public static void main(String[] args) {⭔System.out.println("1st fibonacci number is " + fibonacci(0));⭔System.out.println("2nd fibonacci number is " + fibonacci(1));⭔System.out.println("3rd fibonacci number is " + fibonacci(2));⭔System.out.println("4th fibonacci number is " + fibonacci(3));⭔System.out.println("5th fibonacci number is " + fibonacci(4));⭔System.out.println("11th fibonacci number is " + fibonacci(10));⭔}⭔public static int fibonacci(int num) {⭔if (num == 0) {⭔return 0;⭔}⭔if (num == 1) {⭔return 1;⭔}⭔return fibonacci(num-2) + fibonacci(num-1);⭔}⭔}""",
'33':"""public class RecursionExponents {⭔public static void main(String[] args) {⭔System.out.println("2^5 is: " + pow(2, 5));⭔System.out.println("3^4 is: " + pow(3, 4));⭔System.out.println("6^2 is: " + pow(6, 2));⭔}⭔public static int pow(int base, int exp) {⭔if (exp == 0) {⭔return 1;⭔}⭔return base * pow(base, exp-1);⭔}⭔}""",
'34':"""public class RecursionFactorial {⭔public static void main(String[] args) {⭔System.out.println("5! is: " + factorial(5));⭔System.out.println("4! is: " + factorial(4));⭔System.out.println("3! is: " + factorial2(3));⭔}⭔public static int factorial(int num) {⭔if (num == 1) {⭔return 1;⭔}⭔return num * factorial(num-1);⭔}⭔public static int factorial2(int num) {⭔int fac = 1;⭔for (int i = num; i > 1; i--) {⭔fac = i * fac;⭔}⭔return fac;⭔}⭔}""",
'35':"""public class ClassDemo {⭔public static void main(String[] args) {⭔Animal dog = new Animal("Gigi", 4, "dog");⭔System.out.println(dog);⭔System.out.println("My dog's name is " + dog.name);⭔}⭔}⭔class Animal {⭔public String name;⭔public int legs;⭔public String species;⭔public Animal(String initName, int initLegs, String initSpecies) {⭔this.name = initName;⭔this.legs = initLegs;⭔this.species = initSpecies;⭔}⭔public String toString() {⭔return name + " is a "⭔+ species + " and has " + legs + " legs.";⭔}⭔}""",
'36':"""public class CircleDemo {⭔public static void main(String[] args) {⭔Circle c1 = new Circle(1);⭔System.out.printf("Area of c1 = %.2f \\n", c1.getArea());⭔System.out.printf("Circumference of c1 = %.2f \\n", c1.getCircumference());⭔Circle c2 = new Circle(5);⭔System.out.printf("Area of c2 = %.2f \\n", c2.getArea());⭔System.out.printf("Circumference of c2 = %.2f \\n", c2.getCircumference());⭔}⭔}⭔class Circle {⭔private int radius;⭔public Circle(int radius) {⭔this.radius = radius;⭔}⭔public void setRadius(int newRadius) {⭔radius = newRadius;⭔}⭔public int getRadius() {⭔return radius;⭔}⭔public double getArea() {⭔return Math.pow(radius, 2) * Math.PI;⭔}⭔public double getCircumference() {⭔return 2 * radius * Math.PI;⭔}⭔}""",
'37':"""public class InheritanceDemo {⭔public static void main(String[] args) {⭔Animal bob = new Animal("Bob", 4);⭔Dog amy = new Dog("Amy", 4, "small");⭔System.out.println(bob);⭔System.out.println("Bob: " + bob.speak());⭔System.out.println(amy);⭔System.out.println("Amy: " + amy.speak());⭔}⭔}⭔class Animal {⭔public String name;⭔public int legs;⭔public Animal(String name, int legs) {⭔this.name = name;⭔this.legs = legs;⭔}⭔public String speak() {⭔return "I am an intelligent animal.";⭔}⭔public String toString() {⭔return name + " has " + legs + " legs.";⭔}⭔}⭔class Dog extends Animal {⭔public String size;⭔public Dog(String name, int legs, String size) {⭔super(name, legs);⭔this.size = size;⭔}⭔public String speak() {⭔return "Woof woof!";⭔}⭔}""",
'38':"""public class PrivateDataDemo {⭔public static void main(String[] args) {⭔Person p = new Person("George Washington", 15);⭔System.out.println(p);⭔p.setName("Abraham Lincoln");⭔System.out.println(p);⭔p.setAge(17);⭔System.out.println(p);⭔}⭔}⭔class Person {⭔private String name;⭔private int age;⭔public Person(String name, int age) {⭔this.name = name;⭔this.age = age;⭔}⭔public void setName(String newName) {⭔name = newName;⭔}⭔public void setAge(int age) {⭔this.age = age;⭔}⭔public String toString() {⭔return name + " is " + age + " years old.";⭔}⭔}""",
'39':"""public class PrivateAndInheritance {⭔public static void main(String[] args) {⭔Person p = new Person("George", 15);⭔System.out.println(p);⭔Student s = new Student("Amy", 14, 3.4);⭔System.out.println(s);⭔}⭔}⭔class Person {⭔private String name;⭔private int age;⭔public Person(String name, int age) {⭔this.name = name;⭔this.age = age;⭔}⭔public void setName(String newName) {⭔name = newName;⭔}⭔public void setAge(int age) {⭔this.age = age;⭔}⭔public String toString() {⭔return name + " is " + age + " years old.";⭔}⭔}⭔class Student extends Person {⭔private double gpa;⭔public Student(String name, int age, double gpa) {⭔super(name, age);⭔this.gpa = gpa;⭔}⭔public void setGPA(double gpa) {⭔this.gpa = gpa;⭔}⭔public String toString() {⭔String s = super.toString();⭔return s + " GPA is " + gpa;⭔}⭔}""",
'40':"""public class PublicAndInheritance {⭔public static void main(String[] args) {⭔Vehicle v = new Vehicle("Nissan", "Altima", 4);⭔System.out.println(v);⭔System.out.println(v.drive());⭔System.out.println("----");⭔SUV s = new SUV("Chevrolet", "Tahoe", true);⭔System.out.println(s);⭔System.out.println(s.drive());⭔}⭔}⭔class Vehicle {⭔public String make;⭔public String model;⭔public int doors;⭔public Vehicle(String make, String model, int doors) {⭔this.make = make;⭔this.model = model;⭔this.doors = doors;⭔}⭔public String drive() {⭔return "VROOM VROOM!";⭔}⭔public String toString() {⭔return make + " " + model + "\\n Number of Doors: "⭔+ doors;⭔}⭔}⭔class SUV extends Vehicle {⭔public boolean allWheelDrive;⭔public SUV(String make, String model,⭔boolean allWheelDrive) {⭔super(make, model, 4);⭔this.allWheelDrive = allWheelDrive;⭔System.out.println("super.doors: " + super.doors);⭔}⭔public String drive() {⭔return "HONK HONK!";⭔}⭔public String toString() {⭔String s = super.toString() + "\\n All Wheel Drive: ";⭔if (allWheelDrive) {⭔s += "Yes";⭔}⭔else {⭔s += "No";⭔}⭔return s;⭔}⭔}"""
}
}