#๐Ÿ”’ need help w my feet to meters converter(im new to python)

123 messages ยท Page 1 of 1 (latest)

fervent folioBOT
#

@silver bay

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.

viral trench
#

use codeblocks please... what is this? -_-

silver bay
#

ill remake it

viral trench
#

why you deleted that? You could just edit that...

faint rain
fervent folioBOT
#
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.

faint rain
#

!paste is for big code

fervent folioBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

silver bay
#

ok ill just remake the post

faint rain
#

You can use this one, your call. You don't need to use a gist.

silver bay
odd tartan
#

!code

viral trench
silver bay
#

im very new to python lol this code is gonna hurt yall

faint rain
#
import math
def math.to_feet(meters):
odd tartan
#
def display_menu():
    print("Conversions Menu")
    print("1. Feet to Meters")
    print("2. Meters to Feet")
    print()
    
#does the math
import math
def math.to_feet(meters):
    feet = meters / 0.3048
    return feet

def math.to_meters(feet):
    meters = feet * 0.3048
    return meters

if __name__ == "__main__":
    main()```
faint rain
#

This does not make any sense.

#

Importing "math" is how you use functions that are declared in the math module.

viral trench
#

math.to_feet is already a function...

silver bay
#

ok

faint rain
#

def math.to_feet(meters): should just be: def to_feet(meters):

viral trench
#

i mean wait im confused

silver bay
#

yeah im terrible at ts

odd tartan
viral trench
#

this*

faint rain
# silver bay yeah im terrible at ts

So, let's first get rid of the "math." in the function names. Then run the code to make sure it's "valid" code. (it won't do what you want yet, but let's just make it right)

faint rain
silver bay
#

its valid

faint rain
viral trench
silver bay
#

Store the code that performs the feet to meters and meters to feet conversions in functions within a
module.

Store the code that displays the title in its own function, and store the code that displays the menu in
its own function, but store the rest of the code that gets input and displays output in the main()
function

faint rain
#

Great, so you have functions for ft to meters and vice versa in a module. First part is done.

#

I don't see "code that displays the title in its own function".

#

And, I don't see code that "gets input" or "displays output".

silver bay
#

yeah ill add that rq

odd tartan
# faint rain You're good

sorry but can u ban a kid named alexkso729, trying to pull off some bitcoin scam, told him i have 1.2 mill, some idiot.

#

i can send you the screenshots just not here

odd tartan
#

okay

silver bay
#

i added the input and the title

faint rain
#

Read your instructions carefully: "in
its own function"

silver bay
#

ok

#

did that

faint rain
#

Show the code

silver bay
#

i put it in a func and its valid code

#

no syntax errors

viral trench
#

where is the input?

silver bay
#

oops one sec i thought i put that

#

im so sorry yall are having to help me lol im so bad at this

faint rain
silver bay
#

ok

faint rain
silver bay
faint rain
#

it's overwhelming at first

silver bay
#

it is tbh

odd tartan
faint rain
odd tartan
#

might be if someone falls for it, never know

silver bay
faint rain
#

Ok, so you've defined 4 functions, but haven't used them yet

#

Your original code had this: ```py
if name == "main":
main()

silver bay
#

yeah

faint rain
#

Put that back in, and define a main() function.

#

The main function should call your other functions

silver bay
silver bay
odd tartan
#

!code

fervent folioBOT
#
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.

silver bay
#
def main():

    def to_feet(meters):
        feet = meters / 0.3048
        return feet

    def to_meters(feet):
        meters = feet * 0.3048
        return meters
    def title():
        print("Feet and Meters Converter")
        print()
    def conversion():
        option = int(input("Select a conversion (1/2)"))
        if option == 1:
            f = to_feet(m)
            f = round(f, 2)
        elif:
        option = int(input("Select a conversion (1/2)"))
        if option == 2:
            m = to_feet(f)
            m = round(m, 2)
            
if __name__ == "__main__":
    main()```
faint rain
#

Don't put functions in your functions.

#

You had 4 functions. Leave those alone. Create a new function that calls them... just like converstion calls the other functions.

#

*I have a feeling you're using GPT to generate this stuff, and it's only going to hurt you. *

silver bay
#

im not

#

lol

#

im just very bad at coding

#

i wanna leanr tho

viral trench
silver bay
#

i dont gpt i have had 0 coding experience before the class

#

so this is all extremely new to me

viral trench
#

okay, basically dont do the def... stuff inside a def

#

correct the indentation

#

define functions normally then use them in def main

crimson crypt
#

wait where is your main()?

viral trench
silver bay
#
def main():

    def to_feet(meters):
        feet = meters / 0.3048
        return feet

    def to_meters(feet):
        meters = feet * 0.3048
        return meters

    def title():
        print("Feet and Meters Converter")
        print()

    def conversion():
        option = int(input("Select a conversion (1/2)"))
        if option == 1:
            f = to_feet(m)
            f = round(f, 2)
        elif option == 2:
            m = to_feet(f)
            m = round(m, 2)

if __name__ == "__main__":
    main()```
fervent folioBOT
#

Hey @silver bay!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
crimson crypt
#

i dont think calling main() will work :<>

silver bay
#

ok

crimson crypt
silver bay
#

yeah

crimson crypt
#

want me to give you the answer or try out the input() thing :)

silver bay
#

i mean im trying my best top figure out how to call funcs i have my boom right beside me lol

viral trench
#

you didnt actually did anything inside the main function aside from defining other functions...

crimson crypt
silver bay
#

to start it

crimson crypt
#

you need a for example

def main():
    print("Wow!")

if __name__ = "__main__":
    main()
viral trench
#

call the conversion function in main

crimson crypt
#

Tip:- always import packages on the top

viral trench
#

tip2: dont import a package of you dont need

crimson crypt
silver bay
#

its bad ik

#

im working on it

crimson crypt
#

we can give you the answer right away but you should try it first :) we'll fix the errors :D if we can lol

silver bay
#

i would rather not get the answer striaght away

silver bay
#
    return feet

def to_meters(feet):
    meters = feet * 0.3048
    return meters

def title():
    print("Feet and Meters Converter")
    print()
    print("Conversions Menu")
    print("a. Feet to Meters")
    print(" b. Meters to Feet")

def main():
    title()
    while True:
        display_menu()
        option = input("Select a conversion (a/b): ").lower
def display_menu():
    option = int(input("Select a conversion (a/b)"))
    if option == 'a':
        m = float(input("Enter Feet: "))
        meters = to_feet(f)
        f = round(f, 2)
        print("Feet to Meters:", f)
    elif option == 2:
        f = float(input("Enter Meters: "))
        m = to_feet(f)
        m = round(m, 2)
        print("Meters to Feet:", m)
    another = input("Would you like to perform another conversion? (y/n): ").lower()
    if another != 'y':
        print("Thanks, bye!")
        break
        

if __name__ == "__main__":
    main()```
#

it gives me output now

#

but my break funtion says its outside loop

silver bay
#

Ok

faint rain
fervent folioBOT
#
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.

#

๐Ÿ”’ need help w my feet to meters converter(im new to python)