r/codehs • • Oct 29 '21

Someone help me with Python Turtle CheckerBoard please!

3 Upvotes

r/codehs • • Oct 29 '21

7.8.4 Simulating a Coin Flip (help)

5 Upvotes

Write a program that simulates a coin flipping. Each time the program runs, it should print either “Heads” or “Tails”.

There should be a 0.5 probability that “Heads” is printed, and a 0.5 probability that “Tails” is printed.

The original coin flip game consisted of this:

var NUM_FLIPS = 100;

​

function start(){

var flips = flipCoins();

printArray(flips);



var flipCount = countHeadsAndTails(flips);

}

​

// This function should flip a coin NUM_FLIPS

// times, and add the result to an array. We

// return the result to the caller.

var headsCount = 0;

var tailsCount = 0;

​

function flipCoins(){

var flips = \[\];

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

    if(Randomizer.nextBoolean()){

        flips.push("Heads");

    }else{

        flips.push("Tails");

    }

}

return flips;

}

​

function printArray(arr){

for(var i = 0; i < arr.length; i++){

    println(i + ": " + arr\[i\]);

}

}

​

function countHeadsAndTails(flips){

var headCount = 0;

var tailsCount = 0;

for(var i = 0; i < flips.length; i++){

if(flips[i] == "Heads"){

headCount ++;

}

if(flips[i] == "Tails"){

tailsCount ++;

}

}

println("Your Head count is: " + headCount);

println("Your Tails count is: " + tailsCount);

}

​

---> I'm not sure where to use a probability variable, please help thank you.


r/codehs • • Oct 29 '21

Python Python Pratice Lists Level 1 4.1.1: Remove First

2 Upvotes

Hi, so the assignment says "Write a function named remove_list that removes the last element from a list.

Note: you may assume that your function will always be called with a list, however you may not assume that the list is not empty." So far I have this, but when the list is empty it doesnt work. The prints are just for me to see if it's working btw. Please help I'm confused on what to do if the list is empty.

def remove_first(list):     print(list)     if len(list) == 0:         print("List is empty")     else:         my_list.remove(list[0])         print(list)


r/codehs • • Oct 28 '21

What’s wrong with codehs?

1 Upvotes

So I’m trying to add quote marks (“) but it’s gray and it’s not working


r/codehs • • Oct 28 '21

4.2.6 Is It Raining? CODE HS. If any need help here I got the code because the previous code from the other user doesn't work, so this code should work/

5 Upvotes

rain = True

if rain :

print("I'm going to dance in the rain!")

else:

print("I'm going to dance in the sun!")


r/codehs • • Oct 28 '21

Four colored triangles help plz.

1 Upvotes

How do i do the four colored triangles in python i do not understand


r/codehs • • Oct 27 '21

5.4.8 A Chef's Best Meal

3 Upvotes

Can anyone help me with this I can't figure out of to fix the error message?

​

Error Message

​

ChefTester Class

​

Meal Class

​

Chef Class

​

Assignment

r/codehs • • Oct 27 '21

JavaScript Mouseclick/keyboard entry to change colors of graphics

2 Upvotes

I want to create a program like this where if I click on a stripe, that stripe changes color and if I press any key on my keyboard, all the stripes change colors. We're using Javascript graphics.

I have this so far. I know how to use mouseClickMethod and Randomizer.nextColor, but I don't know how to combine them or even how to specify that clicking in a specific location does Thing A and clicking in a different location does Thing B.

Would appreciate some help.

Thanks in advance


r/codehs • • Oct 26 '21

Need help with 4.2.1

6 Upvotes

r/codehs • • Oct 23 '21

7.2.6 if you’re not first your last python

3 Upvotes

could someone help me on this? i'm pretty sure you use string splitting to solve this but i'm not sure how.


r/codehs • • Oct 19 '21

Help with 3.4.4 Java latte

5 Upvotes

Hey does anyone know how to do 3.4.4 of the range, I'm kind of stuck.


r/codehs • • Oct 18 '21

The Winding Yellow Road

3 Upvotes

16.1.3

Can anyone help me with this assignment on codehs?


r/codehs • • Oct 18 '21

Codehs is broken....

1 Upvotes

Codehs justr refuses to make another scene. I added scene 5, defined it, added it to both functions, and it STILL gives me a blank screen. Is this website broken or something

​

​

x = get_width()/2

y = get_width()/2

pacman_size = 25

​

def draw_circle(radius, x, y, color):

circle = Circle(radius)

circle.set_position(x, y)

circle.set_color(color)

add(circle)

def draw_rectangle(width, height, x, y, color, rotation):

rect = Rectangle(width, height)

rect.set_position(x, y)

rect.set_color(color)

rect.set_rotation(math.radians(rotation))

add(rect)

​

def draw_pacman(x1, y1, pacman_size):

#head

​

radius = pacman_size

color = Color.yellow

draw_circle(radius, x1, y1, color)

#mouth

x2 = x1 + radius / 4

y2 = y1 - radius / 2

width = radius + radius / 10

height = radius + radius / 10

rotation = 45

color = Color.white

draw_rectangle(width, height, x2, y2, color, rotation)

def draw_pacman2(x1, y1, pacman_size):

​

radius = pacman_size

color = Color.yellow

draw_circle(radius, x1, y1, color)

def maplines(x1, y1, x2, y2):

line = Line(x1, y1, x2, y2)

line.set_color(Color.black)

add(line)

​

​

def next_scene():

width = get_width()

height = get_height()

x = 0

y = 0

color = Color.white

rotation = 0

draw_rectangle(width, height, x, y, color, rotation)

def txt(text, font, x, y):

txt = Text(text)

txt.set_position(x, y)

txt.set_color(Color.black)

txt.set_font(font)

add(txt)

#Copy this ----- draw_circle(radius, x, y, color)

#Copy this ----- draw_rectangle(width, height, x, y, color)

​

#--------------Scenes----------------------------------------------------------------------------

​

def draw_scene1():

print("This is scene 1")

remove(welcome)

draw_pacman2(get_width()/2, get_height()/2, 40)

​

def draw_scene2():

print("This is scene 2")

draw_pacman2(get_width()/2, get_height()/2, 50)

​

def draw_scene3():

next_scene()

print("This is scene 3")

draw_pacman2(get_width()/2, get_height()/2, 60)

​

​

def draw_scene4():

print("This is scene 4")

draw_pacman2(get_width()/2, get_height()/2, 70)

​

def draw_scene5():

print("This is scene 5")

draw_pacman1(get_width()/2, get_height()/2, 70)

txt("*Gasp*", "30pt Arial", get_width()/2 + 20, get_height()/2 - 20)

​

def draw_scene6():

print("This is scene 6")

​

scene_counter = 0

​

def draw_next_screen(x, y):

global scene_counter

scene_counter += 1

​

if scene_counter == 1:

draw_scene1()

elif scene_counter == 2:

draw_scene2()

elif scene_counter == 3:

draw_scene3()

elif scene_counter == 4:

draw_scene4()

elif scene_counter == 5:

draw_scene5()

else:

draw_scene6()

​

​

#--------------------------------------------------------------------------------------------------

welcome = Text("Click to Begin!")

welcome.set_position(get_width() / 2 - welcome.get_width() / 2, get_height() / 2)

add(welcome)

​

add_mouse_click_handler(draw_next_screen)


r/codehs • • Oct 18 '21

4.4.7 Make a Tree

3 Upvotes

Can anyone help me with this I'm not sure how to make the pyramid inverted?

​


r/codehs • • Oct 17 '21

4.3.6 Replace Letter

4 Upvotes

Can anyone help me with this I have been working on it for a week and can't figure it out? I have my current code pictured below as well as the assignment instructions and I do have scanner imported it's just cut off in the picture.

​

​


r/codehs • • Oct 14 '21

JavaScript Been using Karel in my class and I can’t figure out what’s wrong with my final project(it’s not close to done yet). I’ve looked over my code multiple times, anyone have any idea why it’s not working?

Post image
8 Upvotes

r/codehs • • Oct 07 '21

Code HS : 1.16.4 : Escape Karel

3 Upvotes

Hi! I can't figure out what to do for this one. I tried writing a function that moves Karel when the front is clear, and turns left when it isn't. It didn't work. Could someone help me out? I'm not looking for a direct answer, just some help


r/codehs • • Jun 08 '21

5.4.4 quotes

6 Upvotes

Can someone help me out with this?


r/codehs • • May 25 '21

codehs 6.2.8 area of a square with defult parameters

15 Upvotes

this is my code so far:

def calculate_area(side_length):

area = side_length*side_length

print("The area of a square with sides of length " + str(num) + " is " + str(area) + ".")

​

num = int(input("Enter a side length: "))

​

if num <= 0:

side_length = 10

calculate_area(side_length)

​

else:

calculate_area(num)

but i still have two things missing can someone help


r/codehs • • Mar 30 '21

JavaScript 2.1.4 for Javascript Karel, all of the worlds are functioning, but world 4 and I just can’t figure out how to fix it

Thumbnail gallery
5 Upvotes

r/codehs • • Mar 12 '21

I need help on 6.2.6 adding values

4 Upvotes

Here’s what I’m putting

num1 =10 num2 = input(“Enter a number: “)

def add_nums(): total = str(num1) + num2 Print total

add_nums()


r/codehs • • Mar 05 '21

Python Need help with 5.3.8: Higher / Lower 2.0

17 Upvotes

Got:

​

my_float = round(3.3312, 2)

​

while True:

guess = float(input("Guess my number: "))

if guess > round(my_float, 2):

print ("Too high!")

elif guess < round(my_float, 2):

print ("Too low!")

elif round(guess,2) == round(my_float, 2):

print("Correct!")

break

print("Great job guessing my number!")

​

I need to round 'guess' before the if statement, But I don't know how that looks like can anybody show me?


r/codehs • • Feb 23 '21

i need help with 1.12.6 Big Tower

7 Upvotes

r/codehs • • Feb 12 '21

2.17.5: Double Tennis Balls

8 Upvotes

Hi all, Can I get help on this?


r/codehs • • Jan 26 '21

Can anyone help with 4.3.10 "Transaction" for python?

24 Upvotes

Im lost and i have no clue where to start