#๐Ÿ”’ my first progrom

99 messages ยท Page 1 of 1 (latest)

lapis flax
#

i want to know what to do with python from here:

ABCD = input("what kind of conversion would you like: Farenheit to Celcius, KM to MI, USD to Euros, or KG to LBS (note it goes other way around to) (A)(B)(C)(D): ")

if ABCD.upper() == "A":
    F_OR_C = input("F or C: ")
    if F_OR_C.upper() == "F":
        TEMP = input("what temp: ")
        yes = float(TEMP) - 32
        conversion = yes / 1.8
        print("your anwser is: " + str(conversion))
        
    if F_OR_C.upper() == "C":
        TEMP = input("what temp: ")
        yes = float(TEMP) * 1.8
        conversion = yes + 32
        print("your anwser is: " + str(conversion))
        
if ABCD.upper() == "B":
    KM_OR_MI = input("KM or MI: ")
    if KM_OR_MI.upper() == "KM":
        DIST = input("what is the distance: ")
        conversion = float(DIST) * 0.62137
        print("your anwser is: " + str(conversion))
        
    if KM_OR_MI.upper() == "MI":
        DIST = input("what is the distance: ")
        conversion = float(DIST) / 0.62137
        print("your anwser is: " + str(conversion))
    
if ABCD.upper() == "C":
    U_E = input("USD or Euros: ")
    if U_E.upper() == "USD":
        amount = input("what is the amount: ")
        conversion = float(amount) / 1.20
        print("your anwser is: " + str(conversion))
        
    U_E = input("USD or Euros: ")
    if U_E.upper() == "EUROS":
        amount = input("what is the amount: ")
        conversion = float(amount) * 1.20
        print("your anwser is: " + str(conversion))
        
if ABCD.upper() == "D":
    KG_OR_LBS = input("KG or LBS: ")
    if KG_OR_LBS.upper() == "KG":
        weight = input("what is the weight: ")
        conversion = float(weight) * 2.2
        print("your anwser is: " + str(conversion))
    
    if KG_OR_LBS.upper() == "LBS":
        weight = input("what is the weight: ")
        conversion = float(weight) / 2.2
        print("your anwser is: " + str(conversion))
sour oakBOT
#

@lapis flax

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.

feral latch
#

!code

sour oakBOT
#
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.

feral latch
#

which Python version are you working with?

lapis flax
#

3.0

feral latch
#

wow, that's like 15 years old?

lapis flax
#

oh uhm

feral latch
#

you should get 3.13

lapis flax
#

idk if its that or not

feral latch
#

well, run it and check?

lapis flax
#

how can i check

feral latch
#

like python, or if you're on Windows, py

lapis flax
#

yeah i have 3.13

feral latch
#

ok, you could improve the code with a match block

lapis flax
#

im using thonny ide

lapis flax
feral latch
#

do fix your syntax highlighting in the first message btw

lapis flax
#

how ๐Ÿ˜ญ im new to this

feral latch
#

do you know how to edit your messages?

#

!code

sour oakBOT
#
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.

lapis flax
#

yeh

feral latch
#

there's the info you need

lapis flax
#

ok got it

#

!code

#

@feral latch so where should i take my python knoledge from here?

feral latch
#

what do you want to do with it?

lapis flax
#

i want to master python

feral latch
#

and do what with it

lapis flax
#

than move to the next easiest language

lapis flax
feral latch
#

nobody can do that

lapis flax
#

also what does the match function do?

feral latch
#

it's a statement, not a function

lapis flax
#

oh whats it do?

feral latch
#

it basically picks the matching block and runs it

#

based on the "case" statements

lapis flax
#

what matching block?

#

just the one before it?

feral latch
#

here it chooses the appropriate "case" block based on the ABCD variable value

lapis flax
#

ooooohhhhh

#

ok

feral latch
#

it's a more elegant way to express your if...else blocks

#

and match does much, much more if you know how to use it

lapis flax
#

huh i may have research that

feral latch
#

learning the syntax of the programming language is important

lapis flax
#

what does the case block do?

lapis flax
feral latch
#

!resources

sour oakBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

feral latch
#

match...case go hand in hand

lapis flax
#

ok so case references match?

#

and how does it reference it?

feral latch
#

I don't understand your question

lapis flax
#

what does case do

feral latch
#

match picks the appropriate case block to continue execution of code in, based on the expression given to match

lapis flax
#

uhm i dont understand :/

#

in this context what is case doing

feral latch
#

the interpreter hits the line with match, ok?

#

then it looks at the value of ABCD

#

then it looks which case block match the value, and runs that block only

#

so if your input "B" when the script runs, where does the interpreter continue execution after line 3?

lapis flax
#

oh i understand it now so when abcd is defined if the case is (whatever the condition is) than it executes the code?

feral latch
#

๐Ÿคฆโ€โ™‚๏ธ

#

answer my question, maybe you did get it

lapis flax
#

yeah thats what i said

feral latch
#

which line does the execution continue in if the value of ABCD is B?

#

after line 3

lapis flax
#

line 18?

feral latch
#

correct

#

if none of the cases match, the execution continues after the match statement

lapis flax
#

ah so if i have a randomizer and none of my preset cases are met i can run other code?

feral latch
#

if you want a catch-all case block, it's customary to add a case _:

#

the _ is just a convention but it could be any named variable

#

this case block is only run if no others match

lapis flax
#

oh yeah i said that i think i get it now

#

so its a elif block?

feral latch
#

in its basic form, yes

#

but match...case can do so much more

lapis flax
#

like what

feral latch
#

well, it's still essentially an if...elif block, but you get some interesting syntactic sugar, like guards: case "A" if something == anything: ...

#

the guard (if) there only runs the block if the expression returns a truthy value

lapis flax
#

OH ok

feral latch
#

I can't claim to know all the ins and outs of match...case myself either, it's a relatively recent feature too

lapis flax
#

ok

feral latch
#

it took 3 full PEPs (Python Enhancement Proposals) to implement fully

#

most new features only require 1

lapis flax
#

oh

#

ok

lapis flax
#

@feral latch

#

can i dm u?

feral latch
#

please don't

lapis flax
#

ok

feral latch
#

I'm not inclined to give private advice

lapis flax
#

ok

sour oakBOT
#
Python help channel closed for inactivity

This help channel has been closed. 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.