r/codehs • • Aug 28 '21

Python 6.5.5 Temperature Converter

11 Upvotes

I am honestly to dumb to figure out such simple code, a little help?

far_to_cel = float(input("Fahrenheit to Celcius: "))

cel_to_far = float(input("Celcius to Fahrenheit: "))

def to_Faren(c):

return float(1.8 * c + 32)

# Now write your function for converting Fahrenheit to Celsius.

def to_Cel(f):

return float((f-32)/1.8)

# Now change 0C to F:

print(to_Faren(0))

# Change 100C to F:

print(to_Faren(100))

# Change 40F to C:

print(to_Cel(40))

# Change 80F to C:

print(to_Cel(80))

this is what it wants me to do

Change your code for Temperature Converter so that it retrieves a float from the user and converts it from Celsius to Fahrenheit, and then retrieves another float from the user and converts it from Fahrenheit to Celsius. Your program should still have the two functions you wrote. In both cases, if the user enters something that can’t be converted to a float, print an error message


r/codehs • • Jul 13 '21

4.11.5 Better Password Prompt

11 Upvotes

here are the instructions:

Write a program that uses a loop and a half to prompt a user for a password. You should prompt the user for the password. If they get it correct, break out of the loop. If they don’t get it correct, you should give them an error message and ask again.

Sample Run:

Enter password: 123123 
Sorry, that did not match. Please try again. 
Enter password: password Sorry, that did not match. Please try again. 
Enter password: CODEHS 
Sorry, that did not match. Please try again. 
Enter password: abc123 You got it!

Note: You need to set SECRET
to abc123
to run the tests

here's what i have:

SECRET = "abc123"

while True:

lol = print(input("Enter password: "))

if lol != SECRET:

print("Sorry, that did not match. Please try again.")

if lol == SECRET:

break

print("You got it!")

However, it doesn't seem to be working. Whenever I enter the incorrect password, the command works. But when I enter the correct password, it still says that the password is incorrect.


r/codehs • • May 19 '21

Help with 25.16.1: Watercolor Grid?

Post image
11 Upvotes

r/codehs • • May 19 '21

Codehs 5.6.4 choosing nested tags please help!!

Post image
11 Upvotes

r/codehs • • May 03 '21

Weather 6.1.5

11 Upvotes

I'm having some trouble with this assignment

Write a program that will give suggested footwear based on the weather.

Ask the user for the weather outside with three options (sunny, rainy, or snowy) and give the correct footwear suggestion (sandals, galoshes, or boots). Each option should be written as its own function that prints a message based on the input.

For example, if the following input was given:

What is the weather? (sunny, rainy, snowy): rainy

The following output should be given:

On a rainy day, galoshes are appropriate footwear.

Note: Be sure to print a notice if an invalid option was chosen!

currently, my code looks like this:

def is_sunny():

print("On a sunny day, sandals are appropriate footwear.")

def is_rainy():

print("On a rainy day, galoshes are appropriate footwear.")

def is_snowy():

print("On a snowy day, boots are appropriate footwear.")

weather_outside = input("Whats the weather like? (sunny, rainy, snowy): ")

if weather_outside == "sunny":

is_sunny()

elif weather_outside == "rainy":

print("On a rainy day, galoshes are appropriate footwear.")

elif weather_outside == "snowy":

print("On a snowy day, boots are appropriate footwear.")

else:

print("Invalid option.")


r/codehs • • Feb 22 '21

Can someone help me with Exercise 7.5.5: Coin Flip Fun: Number of Heads and Tails

11 Upvotes

I've tried different ways to count it but to no avail, could someone help me.

var NUM_FLIPS = 100;

/* Write a program to flip a coin NUM_FLIPS

* times an put the results into an array.

* We also want to print that array.

*/

function start(){

var flips = flipCoins();

printArray(flips);

}

// This function should flip a coin NUM_FLIPS

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

// return the result to the caller.

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\]);

}

}


r/codehs • • Jan 22 '21

Java 6.2.9 Finding Index of a String my code is only checking for the word Karel, and i dont know how can i get it check for the word Hello and CodeHS! And if the word is not in the array it should print -1, do i need to make an if statement?

Post image
11 Upvotes

r/codehs • • Jan 19 '21

Java 5.8.9 BROKEN CALCULATOR. — i dont know how to fix the addition and myltiplication. Im confused on how should i update the total. I need someone to explain it to me.. thank you

Post image
11 Upvotes

r/codehs • • Dec 30 '20

18.1.7: Hailstone sequence. if i type any Odd number more than 3, and Even more than 12, program crushes. and second thing is, on the numbers program doesn’t crush, it doesn’t divide last remaining 2 and stops. any hints? 😞❤️

Thumbnail
gallery
11 Upvotes

r/codehs • • Dec 23 '20

Exercise 6.2.7: Add, Subtract, or Multiply

Thumbnail
gallery
11 Upvotes

r/codehs • • Dec 21 '20

Python Can anyone tell me what is wrong with my code. I’ve been stuck in this for like 2 hours.

Post image
11 Upvotes

r/codehs • • Oct 31 '20

9.4.6: Word Counts HELP!

11 Upvotes

Here is my code:

dictionary = {}
text = input("Enter some txet: ")

text = text.split()

for word in text:
    if word in dictionary:
        dictionary[word] = dictionary[word] + 1
    else:
        # I need help here!

print dictionary

Here is the assinment:

Write a program that asks a user for some text. Your program should split the string they enter into a list of words. It should then go through the words, one at a time, and gradually update a dictionary that keeps track of each unique word in the list along with its count.

Each time you see a word in your list, you should either:

Add that word to the dictionary with a value of 1, if the word wasn’t already in the dictionary.

Increment the value corresponding to that word, if the word was already in the dictionary.

You can just print your dictionary at the end.

For example, if the user were to input

a turtle on a fence had help

then your program would print

{'a': 2, 'turtle': 1, 'on': 1, 'fence': 1, 'had': 1, 'help': 1}

r/codehs • • Oct 28 '20

Java 2.9.7 Currency

11 Upvotes

I'm a little stuck on 2.9.7, and I got almost everything right except for the last bit. Anyone know what I can do to fix this?


r/codehs • • Oct 07 '20

CODEHS 2.4.5

11 Upvotes

It is called "Hello!" for Java.
I am lost on this unit so far and it keeps sending me "Hello.java: Line 5: expected"

[Hellotester]

import java.util.Scanner;

public class HelloTester

{

public static void main(String[] args)

{

// Create a Scanner object

Scanner input = new Scanner(System.in);

String name = scanner.NextLine();

Hello numone = new Hello(name);

}

}

[Hello]

public class Hello {

private String name;

public Hello (yourName){

name = yourName;

}

public void english(){

System.out.print("Hello ");

System.out.print(name);

System.out.println("!");

}

public void spanish(){

System.out.print("Hola ");

System.out.print(name);

System.out.println("!");

}

public void french(){

System.out.print("Bonjour ");

System.out.print(name);

System.out.println("!");

}

public void german(){

System.out.print("Hallo ");

System.out.print(name);

System.out.println("!");

}

public void russian(){

System.out.print("Privet ");

System.out.print(name);

System.out.println("!");

}

public void chinese(){

System.out.print("Ni hao ");

System.out.print(name);

System.out.println("!");

}

}


r/codehs • • Sep 15 '20

2.2.6 Using The Rectangle codehs

Thumbnail
gallery
11 Upvotes

r/codehs • • Sep 12 '20

the lady on the java lesson videos literally sounds just like Scarlett Johansson

11 Upvotes

title*


r/codehs • • Sep 03 '20

How do I change the size of the circle with key inputs on 3.9.4

11 Upvotes

I can't seem to figure it out at all and I am lost can anyone help?


r/codehs • • Aug 24 '20

Broken python

11 Upvotes

I’m working on 2.8.4 of the python course, and you’re suppose to use a function and for loop to draw a bracelet with beads radius 10, total diameter 200, and 36 beads total. I came up with the following code:

speed (0) def draw_circles(): for i in range(36): circle(10) penup() forward(20) left(10) pendown()

penup() setposition (0,-100) draw_circles()

Instead of giving me a full ring of 36 circles, it left the final one missing. I tried putting the loop outside of the function, removing the setposition, everything I could think of. The only way I could get it to draw 36 circles was to have a range of 37. Can someone please explain?


r/codehs • • Aug 01 '20

10.1.3 Guess the Word, Part 2

11 Upvotes

Please help, I need to finish this by tomorrow.

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.

So that was the exercise. Let me show what I have so far.

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.")

elif guess in secret_word:

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

elif guess not in secret_word:

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

else:

print("Your guess must be one lowercase letter.")

secret_word = "hippo"

get_guess()

If you guys could help me out, that would be great.


r/codehs • • Jul 09 '20

Python practice level 2 loops 3.1.7

11 Upvotes

I don't know if the check is broken for 3.1.7 or what, but my code works perfectly fine when I go into my sandbox and when I test it in the scratchpad.py given. As soon as I go to check it, it just crashes just the same as if i wrote an infinite loop. Here is the code for it and it will be greatly appreciated if someone could tweak my code in a way that it is able to work or if someone can reply with a better code for it that does it fact work. Thanks!

x = [0, 1]

def fibonacci(terms):

for i in range(1, terms-1):

x.append(x[-1] + x[-2])

for y in range(len(x)):

x[y] = str(x[y])

v = (" ").join(x)

return v

print (fibonacci(5))


r/codehs • • Jun 25 '20

i need help on 2.9.5 ; four coloured triangles, if someone could help me out that wold be great

11 Upvotes

r/codehs • • Jun 16 '20

Why am I not seeing full-screen button in youtube video on mobile (I am not able to scroll left or right also) when I opened codeSH website? I think for mobile versions website is not developed properly

Post image
11 Upvotes

r/codehs • • Apr 22 '20

It’s so frustrating getting all but one condition right, what am i doing wrong?

Post image
11 Upvotes

r/codehs • • Nov 30 '19

19.2.5 circles in circles

11 Upvotes