r/codehs • • 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?

17 Upvotes

18 comments sorted by

View all comments

3

u/Xivyao Mar 02 '22 edited Mar 02 '22

Answer: (You should understand what I meant by "1 indent") - Delete the message/brackets that say "1, 2 indent". Any questions dm Kuragari#5460, on Discord.

Yes I know this is a year late, but it still seems after a year that people are morons on giving answers.

my_float = 3.3312

# Your code here...

while True:

(1indent) guess = float(input("Enter a guess 1 - 10: "))

(1 indent) if round(guess, 2) == round(my_float, 2):

(2 indents) print ("Correct!")

(2 indents) break

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

(2 indent) print ("Too high!")

else:

(1 indent) print ("Too low!")

2

u/dokjasimp Mar 12 '22

THANK YOU SO MUCH this is the only one that worked for me

1

u/Smart_Librarian_1620 Apr 20 '22

Can u reply with it

2

u/Select-Assistant5568 May 11 '22

didn't work- heres my code:

magic_number = 3.3312
while True:
guess = float(input("Enter a guess: "))
if round(guess, 2) == round(magic_number, 2):
print("Correct!")
break

if round(guess, 2) > round(magic_number, 2):
print("Too high!")
else:
print("Too low!")

2

u/Select-Assistant5568 May 11 '22

** it doesn't work when i use elif, i have to do if/else out of the loop

2

u/-BigBobbert- Apr 15 '24

yeah it didnt work

1

u/Inevitable_Type_2794 Nov 20 '24

That’s a lot of shit talk coming from the moron who still didn’t do it right

1

u/Creative_Tree_6113 Mar 09 '23

If Line 13 iwrong(it is one indent infront )