#๐Ÿ”’ My code's not working properly

18 messages ยท Page 1 of 1 (latest)

tulip solstice
#
print("This is a conversion program from fahrenheit(f) to celsius(C) and vice versa")

temp = None
unit = None

while temp is None:
    try:
        temp = float(input("Enter your temperature please:"))
    except ValueError:
        print("ValueError: could not convert string to float")

while unit not in ("F", "C"):
    unit = input("Please enter the unit ( F/C ):").lower()

    if unit == "F":
        result = round((temp - 30) / 2)
        print(f"{temp} fahrenheit correspond to {result} celsius")
    elif unit == "C":
        result = round(temp * 2 + 30, 3)
        print(f"{temp} celsius corresponds to {result} fahrenheit")

for some reasons, when i get to the unit part, u keep getting "Please enter the unit ( F/C ):" and i don't understand why, help !

lapis pelicanBOT
#

@tulip solstice

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.

#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

fleet geode
#

Hint: after unit = input("Please enter the unit ( F/C ):").lower(), put print(unit) and re-run the code. What do you notice?

tulip solstice
#

doesn't show up

#

just keep going on whth the loo

#

loo^*

#

ah

#

i see

#

no, just show the lower case f and go on with the loo

fleet geode
#

the lower case f
Yep. And what are you checking unit against?

tulip solstice
#

with uppercase unit

fleet geode
#

Yep

tulip solstice
#

and it kept looping because i forgot to put back the last part

#

thx dude, glad u helped !

#

!close

lapis pelicanBOT
#
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.