#๐ need help w my feet to meters converter(im new to python)
123 messages ยท Page 1 of 1 (latest)
@silver bay
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.
use codeblocks please... what is this? -_-
i dont know how to do that
ill remake it
why you deleted that? You could just edit that...
!code is how to make formatted code
!paste is for big 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.
ok ill just remake the post
You can use this one, your call. You don't need to use a gist.
!code
sorry, i did not know that this command exists, im not much used to the python bot
im very new to python lol this code is gonna hurt yall
import math
def math.to_feet(meters):
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()```
This does not make any sense.
Importing "math" is how you use functions that are declared in the math module.
math.to_feet is already a function...
ok
def math.to_feet(meters): should just be: def to_feet(meters):
i mean wait im confused
yeah im terrible at ts
ts?..
this*
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)
sorry sorry, ill let u mb
You're good
its valid
Ok, now what do you need to do?
i will suggest use a constant variable instead of int
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
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".
yeah ill add that rq
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
DM modmail plz.
okay
Read your instructions carefully: "in
its own function"
Show the code
where is the input?
oops one sec i thought i put that
im so sorry yall are having to help me lol im so bad at this
And, the instructions call for a main() function.
ok
It's fine, we like to help (when people want to learn).
i wanna get better at this lol
repetition, and asking lots of questions.
it's overwhelming at first
it is tbh
no ones answering mod mail
give it time, it's not urgent.
might be if someone falls for it, never know
https://paste.pythondiscord.com/MFXQ i added the choice 1 and is it valid
Ok, so you've defined 4 functions, but haven't used them yet
Your original code had this: ```py
if name == "main":
main()
yeah
Put that back in, and define a main() function.
The main function should call your other functions
so i put the main function at the top
how do i do a codeblock like this
!code
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()```
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. *
gpt wont do what they did in line#1
i dont gpt i have had 0 coding experience before the class
so this is all extremely new to me
okay, basically dont do the def... stuff inside a def
correct the indentation
define functions normally then use them in def main
wait where is your main()?
line#2
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()```
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.
ok
so what is the exact prolem in your code? No output?
yeah
want me to give you the answer or try out the input() thing :)
i mean im trying my best top figure out how to call funcs i have my boom right beside me lol
you didnt actually did anything inside the main function aside from defining other functions...
for example you are alling the main() right?
yeah i wanna call a func to give me output for it
to start it
you need a for example
def main():
print("Wow!")
if __name__ = "__main__":
main()
call the conversion function in main
rename your display display_menu() to main
Tip:- always import packages on the top
tip2: dont import a package of you dont need
this is chaotic X_X
we can give you the answer right away but you should try it first :) we'll fix the errors :D if we can lol
i would rather not get the answer striaght away
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
wrong indentation
Ok
my brain hurts X_X
Lower is a function. You need to call lower() to use it
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)