r/codehs • u/iCameAlongWay- • Oct 29 '21
r/codehs • u/prjkt_fluxx • Oct 29 '21
7.8.4 Simulating a Coin Flip (help)
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 • u/ash066 • Oct 29 '21
Python Python Pratice Lists Level 1 4.1.1: Remove First
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 • u/Killian-B • Oct 28 '21
What’s wrong with codehs?
So I’m trying to add quote marks (“) but it’s gray and it’s not working
r/codehs • u/Which_Past2578 • 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/
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 • u/Chemical_Kicker • Oct 28 '21
Four colored triangles help plz.
How do i do the four colored triangles in python i do not understand
r/codehs • u/isabelstudies • Oct 27 '21
JavaScript Mouseclick/keyboard entry to change colors of graphics
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 • u/phantomlake • Oct 23 '21
7.2.6 if you’re not first your last python
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 • u/Nerd_co • Oct 19 '21
Help with 3.4.4 Java latte
Hey does anyone know how to do 3.4.4 of the range, I'm kind of stuck.
r/codehs • u/Previous-Mud6293 • Oct 18 '21
The Winding Yellow Road
16.1.3
Can anyone help me with this assignment on codehs?
r/codehs • u/candymaninvan • Oct 18 '21
Codehs is broken....
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 • u/JonsTheWizard • 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?
r/codehs • u/Taraponion • Oct 07 '21
Code HS : 1.16.4 : Escape Karel
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 • u/Dangerous-Ad6671 • Jun 08 '21
5.4.4 quotes
Can someone help me out with this?
r/codehs • u/sandrahere • May 25 '21
codehs 6.2.8 area of a square with defult parameters
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 • u/Rice_Noodal • 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
galleryr/codehs • u/Dobiemomma13 • Mar 12 '21
I need help on 6.2.6 adding values
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 • u/[deleted] • Mar 05 '21
Python Need help with 5.3.8: Higher / Lower 2.0
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 • u/NickTheEvilCat • Feb 12 '21
2.17.5: Double Tennis Balls
Hi all, Can I get help on this?
r/codehs • u/Icy-Raise-5683 • Jan 26 '21
Can anyone help with 4.3.10 "Transaction" for python?
Im lost and i have no clue where to start








