#๐Ÿ”’ weird issue when i try executing my code

141 messages ยท Page 1 of 1 (latest)

lethal gyro
#
C:\Users\Hammad\AppData\Local\Programs\Python\Python312\python.exe: can't open file 'C:\\Users\\Hammad\\PycharmProjects\\K TO L V2\\K TO L V2.py': [Errno 2] No such file or directory
north notchBOT
#

@lethal gyro

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.

spiral moss
#

I mentioned before you should really avoid spaces in filenames

lethal gyro
#

no

#

this issue is weird

#

its not related to my code i think

spiral moss
#

Can you show your pycharm window?

lethal gyro
spiral moss
#

Why?

#

Show it here

lethal gyro
#

u there?

spiral moss
#

No, please don't DM me. If you have any questions about python, you can ask it here

lethal gyro
#

how do i show u my screen

spiral moss
#

take a screenshot

lethal gyro
#

k

gritty kelp
#

You can share screenshots here

lethal gyro
spiral moss
#

I don't see a file with V2 in the name

lethal gyro
#

oh i fixed it...

spiral moss
#

sounds like an old file that you deleted

lethal gyro
#

i did current file and it showed me the error

lethal gyro
#

current file fixes

#

i reversed it or sum again lol

spiral moss
#

but seriously don't use spaces in your file names

#

it will cause issues later on

lethal gyro
#

ok

#
weight_choice = float(input("Enter your weight: "))
unit_choice = input("Which unit do you want to choose (KG OR LBS): ")
if unit_choice == "KG":
    weight_choice == weight_choice*2.205
    print(weight_choice)
elif weight_choice == "LBS":
    weight_choice == weight_choice/2.205
    print(weight_choice)

does it look fine

#

@spiral moss

spiral moss
#

I mentioned previously that you shouldn't reuse the weight_choice variable for the new result

#

make a new variable

#

and I thought you were going to try and add a loop to it?

lethal gyro
#

so i dont get confused too much

spiral moss
#

your variable weight_choice is the name you use for the input, but then you also use it for the converted result

#

so you're overwriting the old data

#

now you have no way of ever displaying to the user what their original value was

#

if you create a new variable, then you'll have more information

lethal gyro
#

OHH WAIT

#

Oh yes

#

new variable

#

ok

lethal gyro
spiral moss
#

why would a string be in it?

#

It would be the result of your conversion

#

instead of reassigning it back to weight_choice, make a new variable

lethal gyro
spiral moss
#

why does it have to be a string?

lethal gyro
#

Um

spiral moss
#

weight_choice == weight_choice*2.205

lethal gyro
#

yeah

spiral moss
#

right now you're doing this for your conversion

#

I'm saying don't use the name weight_choice here

#

weight_choice = float(input("Enter your weight: "))

#

you're already using that name here

#

don't reuse the same name

lethal gyro
spiral moss
#

pick a meaningful name

lethal gyro
#

i suck at that

spiral moss
#

I also just realized you're using == here

#

it should be =

lethal gyro
#

If I don't reuse py weight_choice
when doing py weight_choice = weight_choice*2.205
How would I multiply the weight with 2.205

spiral moss
#

the right side of the = is correct

#

use a different name on the left side

merry root
#

he can just rewrite the variable

lethal gyro
spiral moss
# merry root why?

sure, but if you want to improve on the code by printing a message saying something involving their original weight, you can't

#

If the meaning of a variable has changed, it's best to use a different name

lethal gyro
#
weight_choice = weight_choice_two*2.205

this?

spiral moss
#

no, you have it flipped

#

and pick a meaningul name

lethal gyro
#

Oh i get it

#

only the left one has to be same cuz its multiplying

spiral moss
lethal gyro
merry root
spiral moss
#

the right side of the = is always evaluated first

lethal gyro
#

ye i suck at left right

spiral moss
#

then assigned to whatever is on the left of the =

merry root
#

lol

lethal gyro
#
weight_choice = float(input("Enter your weight: "))
unit_choice = input("Which unit do you want to choose (KG OR LBS): ")
if unit_choice == "KG":
    weight_choice_two = weight_choice*2.205
    print(weight_choice)
elif weight_choice == "LBS":
    weight_choice_two = weight_choice/2.205
    print(weight_choice)
#

This right?

#

Think i got it right

merry root
#

yea

#

try to run it

lethal gyro
#

k

spiral moss
#

yes, but now you can avoid printing twice

#

you can just print after the conditions

lethal gyro
#

theres a problem

merry root
#

yea trye

lethal gyro
#

when i type weight 24

merry root
lethal gyro
#

it gives answer 24.0

#

i reversed again or sum

spiral moss
#

Yes, you're still printing the old message

#

you need to update it

merry root
#

use int(weight)

spiral moss
merry root
lethal gyro
#

this aint it

#

im converting lbs to kg here

spiral moss
#

you've made a new variable

#

that's what you should be printing

#

also use a better name like converted_weight

lethal gyro
#

oh yeah

merry root
#

oooh

lethal gyro
#

i always forget small details

spiral moss
#
weight_choice = float(input("Enter your weight: "))
unit_choice = input("Which unit do you want to choose (KG OR LBS): ")
if unit_choice == "KG":
    converted_weight = weight_choice*2.205
elif weight_choice == "LBS":
    converted_weight = weight_choice/2.205
print(converted_weight)  # Only one print needed
merry root
#

check DMs later @lethal gyro

spiral moss
#

Learning how to debug your code is an important skill to practice

#

and if you only rely on others to solve your mistakes, you'll never learn

merry root
spiral moss
lethal gyro
#

OH GOT SMTH IS WRONG AGAIN

merry root
#

lol

#

whats that now?

spiral moss
#

look it over

lethal gyro
#

k

spiral moss
#

think about what each line does

#

think about if something isn't where it should be

#

think about what each variable represents

#

you can use extra prints to see what certain variable's values are

#

and see if they're what you expect

lethal gyro
#

fixed it

#

I was multiplying 2.205 on the first conversion i had to divide

#

i gotta go somewhere i be back in 10 mins and then ima try the loop

#

k back

#

gotta eat now xd

north notchBOT
#
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.