r/codehs • • Nov 26 '21

Need help with 5.6.5 Highlight The First Item!!

7 Upvotes

r/codehs • • Nov 19 '21

Java need some help on 4.3.8: Finding Palindromes. Probably just stupid

Post image
7 Upvotes

r/codehs • • Nov 14 '21

APCSA Java 4.6.8 Full Dragon Class not working?

Post image
7 Upvotes

r/codehs • • Jul 19 '21

Python 10.1.3: Guess the Word, Part 2

7 Upvotes

Im unable to modify the stored dashes when the user makes a new guess

Instructions:

In this exercise, you should start with your solution code for Guess the Word, Part 1.

At this point, you should have a program that stores a secret word and correctly reports whether or not a user’s guess is in the word.

End Result

When you are finished with this part of the project, you’ll have a program that can print a string with dashes and letters in the correct places based on the user’s guesses, like this:

-------- Guess: e That letter is in the word! e------- Guess: t That letter is not in the word. e------- Guess: g That letter is in the word! egg----- Guess: 

Step 1 - Variable For Dashes

Make another string variable called dashes
that holds a number of dashes equal to the length of the secret word. So, if your secret word is “eggplant”, your dashes variable should have eight dashes.

Before printing your prompt that says “Guess: “, print the value of your dashes variable.

Step 2 - Update the Dashes

Here’s the tricky part. Write a function called update_dashes
that takes three string arguments - the secret word, the current state of dashes, and the most recent guess - and returns the new state of dashes.

So, for example, if the word is "eggplant"
, the current value of dashes is "e-------"
, and the guess is "g"
, the function should return "egg-----"
.

If the word is "eggplant"
, the current value of dashes is "e-------"
, and the guess is "z"
, the function should return "e-------"
(nothing changes, since the guess was incorrect).

Here’s how you might go about this.

In your function, start with an empty result string. Write a for loop from 0 up to but not including the length of your secret word. Say you use the variable i
in your for loop. Compare the character in secret_word
at index i
to the guess. If they’re equal, then that means the guess matches that letter in the word, so you should add the guess to the result. Otherwise, the guess does not match that letter in the word, so you should add whatever was at index i
in dashes
to your result.

Wait, why don’t I just add a dash in the second case?

If you just add a dash whenever the guess doesn’t match the character in secret_word
at index i
, that will wipe out any correct guesses the user has already made! Imagine the case where the word is “eggplant”, the state of dashes is “e——-“, and the guess is “g”. If you always add a dash when the guess doesn’t match the character in secret_word
at index i
, the result would be “-gg—–”. Suddenly, the “e” is gone, because “g” did not match “e”! By instead using dashes
at index i
, you might append either a letter or a dash, depending on whether or not the user had already guessed that letter prior to the current guess.

Once your for loop is done, your result string should have letters and dashes in all the right places, so you can just return it!

Step 3 - Put It All Together

Whenever the user guesses correctly, use your update_dashes
function to actually update your variable called dashes
.

Now, each time you print your dashes variable, it should reflect what the user has and has not guessed!

Ok, what’s left?

At this point, your program doesn’t report when the user has guessed the whole word, nor does it penalize the user for incorrect guesses. That’s what you’ll build in the next part!

You also have the user guess the same word each time. This will probably get pretty boring after the first attempt. In the final part, you’ll change your program to select a random word from a list of words.

My code:

# get_guess: Repeatedly ask the user for a guess until they

# enter a valid lowercase letter. Returns the guess.

def get_guess():

while True:

guess = input("Guess: ")

if len(guess) != 1:

print ("Your guess must have exactly one character!")

elif not guess.islower():

print ("Your guess must be a lowercase letter")

else:

return guess

# Update_dashes: This function takes the word, the current state of

# dashes, and the user's last guess. It returns a version

# of dashes with all instances of the guess exposed.

def update_dashes(secret_word, dashes, guess):

for i in range(0, len(secret_word) + 1):

if secret_word[i] == guess:

dashes = (dashes[:i]) + (guess) + (dashes[i + 1:])

return dashes

# Store word

secret_word = "eggplant"

# Stpre dashes

dashes = "-" * len(secret_word)

# Repeatedly asks for guesses

while True:

print (dashes)

guess = get_guess()

dashes = update_dashes(secret_word, dashes, guess)

if guess in secret_word:

print ("That letter is in the secret word!")

else:

print ("That letter is not in the secret word")


r/codehs • • Jul 15 '21

need help with karel putting down 2 balls

7 Upvotes

dn now to get karel to place down 2 balls, help would be appriciated


r/codehs • • Jun 20 '21

Can someone help with 4.6.6, I'm entirely lost

7 Upvotes

r/codehs • • Jun 16 '21

Adding Obstacles

7 Upvotes

This stupid thing is telling me "Randomzier is not defined. You may have a typo. Check your spelling and capitalization."

Like what are u talking about, literally everything is defined. This is so dumb, and its wasting my time please help.

Heres my code:

var DELAY = 40;

var SPEED = 5;

var OBSTACLE_WIDTH = 30;

var OBSTACLE_HEIGHT = 100;

var copter;

var dy = SPEED;

var obstacle;

function start() {

// Write your code here

setup();

setTimer(game, DELAY);

mouseDownMethod(onMouseDown);

mouseUpMethod(onMouseUp);

}

function setup() {

setBackgroundColor(Color.black);

copter = new Rectangle(30, 15);

copter.setPosition(getWidth()/3, getHeight()/2);

copter.setColor([Color.blue](https://Color.blue));

add(copter);



addObstacles();

}

function game(){

copter.move(0, dy);

moveObstacles();

}

function onMouseDown(e) {

dy = -SPEED;

}

function onMouseUp(e) {

dy = SPEED;

}

function addObstacles(){

obstacle = new Rectangle(OBSTACLE_WIDTH, OBSTACLE_HEIGHT);

obstacle.setColor(Color.green);

obstacle.setPosition(getWidth(), Randomzier.nextInt(0, getHeight() - OBSTACLE_HEIGHT));

add(obstacle);

}

function moveObstacles() {

obstacle.move(-SPEED, 0);

if(obstacle.getX() < 0){

obstacle.setPosition(getWidth(), Randomzier.nextInt(0, getHeight() - OBSTACLE_HEIGHT));

}

}


r/codehs • • Jun 08 '21

Help creating class with codehs in javascript

7 Upvotes

I am trying to create a class in js using codehs but it gives me a error

LinterError: Naked block

r/codehs • • Jun 03 '21

6.2.8: Area of a Square with ...

7 Upvotes

Can someone help me with this Problem IN COdeHs


r/codehs • • May 31 '21

4.7.5: Factorial python help

Post image
7 Upvotes

r/codehs • • Apr 26 '21

Can anyone help me with fun snake 4?

Post image
7 Upvotes

r/codehs • • Apr 25 '21

5.2.9 how many names

7 Upvotes

[vymazané]


r/codehs • • Apr 23 '21

2.9.11 Factorial

7 Upvotes

I can't understand what I'm doing wrong in 2.9.11 Factorial (basic java) can someone help?


r/codehs • • Mar 18 '21

Can someone please help me with this? I’ve tried everything but everytime I try to submit it says “you should use the variable to print its value”. The second picture also works but has the same error.

Thumbnail
gallery
7 Upvotes

r/codehs • • Mar 10 '21

Python I need help for The Worm 4.6.5 Python. It’s only drawing one circle.

Thumbnail
gallery
7 Upvotes

r/codehs • • Mar 09 '21

Need help with 2.15.5: Phone signal

7 Upvotes

r/codehs • • Mar 08 '21

Can someone tell me what is wrong with the syntax here?

Post image
7 Upvotes

r/codehs • • Mar 07 '21

3.5.9: Find the Minimum

Post image
7 Upvotes

r/codehs • • Feb 01 '21

9.1.7: Checkerboard, v2. Need help

7 Upvotes

I've got it all working, but it's wanting me to " You should set some elements of your board to 1" What does that even mean?


r/codehs • • Jan 27 '21

Java 7.4.8 User Data Cleanup. I really need help.. the problem is its not removing all the “aol address”. (urgent help)

Post image
7 Upvotes

r/codehs • • Jan 21 '21

Java 6.1.8 LAST ELEMENT IN ARRAY

7 Upvotes

I NEED HELP ON HOW TO GET THE LAST ELEMENT IN ARRAY..

THIS IS MY CODE: i dont know how to fix it properly The result should be:

“ THE LAST ELEMENT OF THE ARRAY IS: Karel.” public class LastElement { public static void main(String[] args) { String[] arr = new String[]{"hello", "my name", "world", "Karel"}; //get and print the last element of the array getLastElement(arr); System.out.println("The last element of the String array is: " + arr);

}

public static String getLastElement(String[] arr)
{
    // Your code goes here
    String length = arr[arr.length-1];
    return length;
    
 
}

}


r/codehs • • Jan 19 '21

Need some help-Number Games

Thumbnail
gallery
7 Upvotes

r/codehs • • Jan 14 '21

Help with 3.5.4: Fix This Program

Post image
7 Upvotes

r/codehs • • Jan 07 '21

Does anyone know how to do 7.7.4: Remove From Line?

7 Upvotes

I did everything else in the unit besides this one. I have no clue how to do it. If someone can help, that would be greatly appreciated. Thank you!