0

I am really new to coding in general and started Python only recently, and am working on some really beginner practice problems... And I'm working on if and else functions. I followed the tutorial (from yt with exact code) and can't figure out why it won't register correctly.

The practice problem is a simple weight converter from kg to lbs using if and else functions.

weight = int(input("Weight: "))
kg_lbs = input("(K)g or (L)bs?")
converted_one = weight / 0.454
converted = weight * 0.45
if kg_lbs.upper == "K":
 print("Weight in lbs: " + str(converted_one))
else:
 print("Weight in kgs: " + str(converted))

When k is entered from input, it is meant to print "Weight in lbs: " + str(converted_one)), but it just doesn't register the code and does the else code. And if I remove the else code or replace it w/ something simple such as print("done"), and run it again, it will just continue to skip the if code and do the else code...

The yt video I used for reference is (https://www.youtube.com/watch?v=kqtD5dpn9C8) at 41:00.

asked Nov 7, 2021 at 3:01
1
  • 8
    .upper is a function: .upper(). Also, you might want to consider renaming you 'converted' variables to something more specific. Commented Nov 7, 2021 at 3:06

1 Answer 1

2

As @Larry the Llama says in the comment, upper is a function, so you need to use it like this:

some_string.upper()
answered Nov 7, 2021 at 3:11
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.