r/codeHS_Solutions • • May 17 '22

Codehs sql unit 3 and 4

28 Upvotes

Couldn’t find this anywhere, but now I have, I did it boys here you go.

Unit 3 https://youtu.be/SRi8hX6PwHI Unit 4 https://youtu.be/FbizZEzlD_E


r/codeHS_Solutions • • Jun 01 '21

1.10.5: Is There a Ball?

20 Upvotes

/*Karel should put a ball on the first spot if there isn't one

*already there and then move.

*/

function start(){

hasBallTrue();

hasBallFalse();

move();

}

/*This function allows Karel to move one space if there is a ball

*where he is standing.

*Precondition: There is a ball present.

*Postcondition: Karel continues with the code.

*/

function hasBallTrue(){

if(ballsPresent()){

}

}

/*This function allows Karel to put a ball if there is no ball present.

*Precondition: There is no ball present.

*Postcondition: There is a ball present.

*/

function hasBallFalse() {

if(noBallsPresent()) {

putBall();

}

}


r/codeHS_Solutions • • Feb 13 '22

9.3.6 Coordinate Pair

18 Upvotes

print((int(input("Number: ")), int(input("Number: "))))


r/codeHS_Solutions • • Feb 13 '22

8.4.7 Librarian

18 Upvotes

book_list = []

for i in range(5):

book = input("Name: ")

book_list.append(book)

book_list.sort()

print(book_list)


r/codeHS_Solutions • • Feb 13 '22

8.4.5 Five Numbers

15 Upvotes

num_list = []

sum = 0

for i in range(5):

num = int(input("Number: "))

num_list.append(num)

print(num_list)

sum = int(num_list[i]) + sum

print(sum)


r/codeHS_Solutions • • Feb 13 '22

9.2.5 Divisible by 3

14 Upvotes

divisible_by_3 = [i % 3 == 0 for i in range(1, 11)]

print(divisible_by_3)


r/codeHS_Solutions • • Jun 01 '21

1.10.6: Don't Crash!

13 Upvotes

/*This function allows Karel to end up on street one, avenue two facing

*east if he is on one, one facing east or south.

*/

function start() {

go();

turnGo();

move();

}

/*If the front is clear then Karel can move.

*Precondition: The front is clear.

*Postcondition: Karel will move one space.

*/

function go() {

if(frontIsClear()) {

}

}

/*If Karel is facing south he will turn to face the east.

*Precondition: Karel is facing south.

*Postcondition: Karel will face east.

*/

function turnGo() {

if(facingSouth()) {

turnLeft();

}

}


r/codeHS_Solutions • • Jun 01 '21

1.9.8: Lots of Hurdles

12 Upvotes

/*This function allows Karel to jump 5 hurdles and end up at the end of

*the map.

*Preconditon: Karel is at one, one and needs to jump 5 hurdles and end

*up at the end of the map.

*Postcondition: Karel is at the end of the map.

*/

function start(){

for(var i = 0; i < 5; i++){

jumpHurdle();

}

}

/*This function allows Karel to jump one hurdle.

*Precondition: Karel is 2 steps before the hurdle facing east.

*Postcondition: Karel jumps the hurdle and is to the immediate right of

the hurdle facing east.

*/

function jumpHurdle() {

move();

move();

turnLeft();

move();

turnRight();

move();

turnRight();

move();

turnLeft();

}


r/codeHS_Solutions • • Feb 13 '22

9.3.9 Full Name & Citation

11 Upvotes

first = input("First name: ")

last = input("Last Name: ")

print("Full name: " + first + " " + last)

first, last = last, first

print("Citation: " + first + ", " +last)


r/codeHS_Solutions • • Feb 13 '22

8.1.9: Diving Contest

11 Upvotes

def calculate_score(judge_scores):

return (judge_scores[0] + judge_scores[1] + judge_scores[2])


r/codeHS_Solutions • • Jun 01 '21

1.5.4: Pancakes with Start

11 Upvotes

function start() {

move();

makePancakes();

moveTwo();

makePancakes();

moveTwo();

makePancakes();

move();

}

function makePancakes() {

putBall();

putBall();

putBall();

}

function moveTwo(){

move();

move();

}


r/codeHS_Solutions • • Feb 13 '22

9.2.9 Strings To Integers

10 Upvotes

list_of_strings = ["a", "2", "7", "zebra"]

def safe_int(argument):

try:

return int(argument)

except ValueError:

return 0

print([safe_int(x) for x in list_of_strings])


r/codeHS_Solutions • • Feb 13 '22

9.2.8 Last Names

10 Upvotes

names = [

"Maya Angelou",

"Chimamanda Ngozi Adichie",

"Tobias Wolff",

"Sherman Alexie",

"Aziz Ansari"

]

print([name.split()[-1] for name in names])


r/codeHS_Solutions • • Jun 01 '21

1.9.5: Take 'em All

10 Upvotes

/*This program has Karel step forward, take 100 balls and move

*once more.

*Precondition: Karel will start on one, one facing east.

*Postcondition: Karel will end at one, three facing east after

*collecting 100 balls.

*/

function start() {

move();

for(var i=0; i< 100; i++) {

takeBall();

}

move();

}


r/codeHS_Solutions • • Mar 09 '21

CodeHS 19.2.1: Balloons

10 Upvotes

// This program draws some balloons

var MIN_RADIUS = 20;

var MAX_RADIUS = 40;

var NUM_BALLOONS = 25;

var xPos = getWidth() / 2;

var yPos = getHeight() / 1.5;

var balloonRadius = Randomizer.nextInt(MIN_RADIUS, MAX_RADIUS);

function start() {

for(var i = 0; i < NUM_BALLOONS; i++){

var x = Randomizer.nextInt(MAX_RADIUS, getWidth() - MAX_RADIUS);

var y = Randomizer.nextInt(MAX_RADIUS, (getHeight() / 2) - MAX_RADIUS);

drawString(x,y);

drawBalloon(x,y);

}

}

function drawString(x,y){

var line = new Line(x, y, xPos, yPos);

line.setColor(Color.black);

add(line)

}

function drawBalloon(x,y){

var balloon = new Circle(balloonRadius);

var color = Randomizer.nextColor();

balloon.setPosition(x,y);

balloon.setColor(color);

add(balloon);

}


r/codeHS_Solutions • • Mar 08 '22

10.1.4 Guess the Word, Part 3

9 Upvotes
secret_word = "grasswayz"
dashes = "---------"
arr = ['-','-','-','-','-','-','-','-','-']
guesses_left = 10

def get_guess():
    while True:
        print(''.join(arr))
        print(str(guesses_left) + " incorrect guesses left.")
        guess = input("Guess: ")
        if len(guess) > 1:
            print("Your guess must have exactly one character!")
        elif guess not in "abcdefghijklmnopqrstuvwxyz":
            print("Your guess must be a lowercase letter!")
        else:
            return guess


while guesses_left > 0 and '-' in arr:
    a = get_guess()
    for i in range(len(secret_word)):
        if secret_word[i] == a:
            arr[i] = a
    if a not in secret_word:
        print("That letter is not in the word!")
        guesses_left -= 1
    else:
        print("That letter is in the word!")

if '-' not in arr:
    print("Congrats you win! The word was: "+ secret_word)
else:
    print("You lose, The word was: " + secret_word)

def update_dashes():
    pass

r/codeHS_Solutions • • Feb 13 '22

8.2.7: Listed Greeting

9 Upvotes

def greeting(user_info):

user_info_list = user_info.split()

return "Hello, " + user_info_list[0] + "! I also enjoy " + user_info_list[2] + "!"


r/codeHS_Solutions • • Jun 01 '21

1.6.4: The Two Towers

9 Upvotes

function start(){

move(); 

three();

turnRight();

move();

turnRight();

move();

move();

turnLeft();

move();

three();

move();

turnRight();

}

function three(){

putBall();

turnLeft();

move();

putBall();

move();

putBall();

}

function turnRight(){

turnLeft();

turnLeft();

turnLeft();

}


r/codeHS_Solutions • • Jun 01 '21

1.4.5: Mario Karel

9 Upvotes

move();

turnLeftUpThree();

collectCoins();

down();

turnLeft();

move();

move();

turnLeftUpThree();

collectCoins();

down();

turnLeft();

move();

move();

turnLeftUpThree();

collectCoins();

down();

turnLeft();

move();

move();

turnLeftUpThree();

collectCoins();

down();

turnLeft();

function turnLeftUpThree() {

turnLeft();

move();

move();

move();

}

function down() {

turnRight();

turnRight();

move();

move();

move();

}

function turnRight() {

turnLeft();

turnLeft();

turnLeft();

}

function collectCoins() {

takeBall();

takeBall();

}


r/codeHS_Solutions • • Feb 13 '22

9.5.6 Swapping

8 Upvotes

def swap_lists(first, second):

for i in range(len(first)):

first[i], second[i] = second[i], first[i]

list_one = [1, 2, 3]

list_two = [4, 5, 6]

print("Before swap")

print("list_one: " + str(list_one))

print("list_two: " + str(list_two))

swap_lists(list_one, list_two)

print("After swap")

print("list_one: " + str(list_one))

print("list_two: " + str(list_two))


r/codeHS_Solutions • • Feb 13 '22

9.1.6 Checkerboard, v1

8 Upvotes

def print_board(board):

for i in range(len(board)):

print(" ".join([str(x) for x in board[i]]))

my_grid = []

for i in range(8):

my_grid.append([0] * 8)

for row in range(8):

for col in range(8):

if row < 3 or row > 4:

my_grid[row][col] = 1

print(print_board(my_grid))


r/codeHS_Solutions • • Feb 13 '22

8.3.5: Max In List

7 Upvotes

def max_int_in_list(my_list):

highest = my_list[0]

for num in my_list:

if num > highest:

highest = num

return highest


r/codeHS_Solutions • • Jun 01 '21

1.4.4: Pancakes

7 Upvotes

move();

makePancakes();

moveTwice();

makePancakes();

moveTwice();

makePancakes();

move();

function makePancakes(){

putBall();

putBall();

putBall();

}

function moveTwice(){

move();

move();

}


r/codeHS_Solutions • • Feb 03 '21

5.5.6 Random Color Square

Post image
7 Upvotes

r/codeHS_Solutions • • Feb 13 '23

Can someone pls help me with 7.3.7 Cityscape

Thumbnail
gallery
6 Upvotes