#๐Ÿ”’ What do y'all think of my code ?

89 messages ยท Page 1 of 1 (latest)

gleaming jewel
#
print("This is a conversion program from pounds(lb) to kilograms(kg) and vice versa")
try:
    weight = float(input("Enter your weight please:"))
except ValueError:
    print("Please enter a valid number, thank you.")
    exit()

unit = input("Please enter the unit ( lb/kg ):")

if unit == "lb":
    result = round(weight / 2.2046, 3)
    print(f"{weight} pounds correspond to {result} kilograms")
elif unit == "kg":
    result = round(weight * 2.2046, 3)
    print(f"{weight} kilograms corresponds to {result} pounds")
else:
    print("Please enter a valid unit.")
west carbonBOT
#

@gleaming jewel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tepid spindle
#

it's quite basic but it works

#

good job for using f strings

gleaming jewel
#

thx to brocode tbh

tepid spindle
#

look into while loops

gleaming jewel
#

right now i just wanted to prove a point to my brother

#

but ima do that in the futur

tepid spindle
#

it's fine

gleaming jewel
#

and tbh, i just took BroCode's code (from his "Python weight conversion exercise ๐Ÿ‹๏ธ" video) and tried to make it better

#

and hey, i think i didn't do a terrible job, quite good in my opinion

tepid spindle
#

it works just fine

gleaming jewel
#

the try and except part was VERY long tho

#

i had a hard time understanding it lol

wintry ocean
#

I'd say do unit.lower()

trim bluff
#

great code op but during the input when the user enters a string or something else which isnt a float it end the program u can improve it by asking for the input again instead

wintry ocean
#

just in case someone types in KG or something

gleaming jewel
tepid spindle
#

and for the unit too

tepid spindle
wintry ocean
tepid spindle
#

lowercase

gleaming jewel
#

so if they type KG Kg kG and kg it all works ?

#

or just kg and KG

wintry ocean
#

yep

trim bluff
#

yeah

gleaming jewel
#

cool !

#

ima try to do that

wintry ocean
#

just add a .lower() to the end of your unit input section

gleaming jewel
#

thx !

wintry ocean
#

np!

#

but good code overall

gleaming jewel
#

or did i just not understand ?

#

cuz when i do that here is the warning i got :

wintry ocean
#

I was saying more like : unit = input("Please enter the unit ( lb/kg ):").lower()

gleaming jewel
#

oh crap i typed unit instead dof lower

#

now it's a complytely different error

#

tf does it mean name expected

#

huh

#

it resolved itself

#

it's soooo cool

#

it works even better now !

wintry ocean
#

yay!

#

im glad for you

gleaming jewel
#

thx dude, ur the best

#

๐Ÿ™‚

wintry ocean
#

np, have fun with python

gleaming jewel
#

i AM having fun

#

my final challenge will be to try and code a game

wintry ocean
#

im in the middle of making a game

gleaming jewel
#

i think it can be cool

#

oooh

#

that's cool

wintry ocean
#

looks like this so far

gleaming jewel
#

well, i hope ur having fun too !

wintry ocean
#

thx!

gleaming jewel
wintry ocean
#

thanks man

gleaming jewel
#

it looks like a car lol, but what is it ?

wintry ocean
#

it is a car, with zombies around it

#

its like semi 3d

gleaming jewel
#

can see it

#

it looks really cool

wintry ocean
#

I would send a video of it, but I can't in here

gleaming jewel
#

discord isn't really made to send video

wintry ocean
#

It's just this server specifically, it doesn't allow it

gleaming jewel
#

really ?

#

u can't send any links ?

#

ya no it's possible

gleaming jewel
#

damn it's cool

wintry ocean
#

thx

gleaming jewel
#

the semi 3d is really well done

#

i can see the car inside the sidewalk time to times, is it possible to fall of ?

wintry ocean
#

nope, its got collisions

#

the z order is just a bit funky

gleaming jewel
#

it's literaly inside the sidewalk

wintry ocean
#

you cant drive through it, the collison is just in the wrong spot

#

its still super early stages

gleaming jewel
#

it's still cool

wintry ocean
#

thanks

gleaming jewel
#

is gyazo the game ?

wintry ocean
#

gyazo is just what i used to record it

gleaming jewel
#

oooh

#

that's cool

west carbonBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.