#๐ I'm stuck on my code
81 messages ยท Page 1 of 1 (latest)
@vale sundial
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.
!code
I was watching a tutorial where we were making a restaurant and we needed to convert a string to an integer
But when I try to I get an error
TypeError: can only concatenate str (not "int") to str
the full error
you're tryna do 5 + "hello"
on that line, (the variable should be marked in the traceback) you're adding a number and a string together, which python forbids because that just doesn't make sense
the tutorial guy did it and it worked
show us your code
ok
probably not a good tutorial then
just send it?
yeah
if it involves a hint of black magic
!paste
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.
in here
i'm on mobile
i can't see syntax highlighting
that's why i said to use the pastebin regardless
!code
discord has builtin syntax highlighting
i can't see syntax highlighting
not yet for iOS
oh i didnt know that
yep. awful state of affairs
do I send the code file or what
link
whole point of a pastebin is that you share files by link
ohh
paste it in the pastebin and then sent the link
https://paste.pythondiscord.com/QC2Q like this?
yeah
last line
i recommend you use f strings for this instead
string interpolation is a common technique
yes
sorry I'm brand new to Python could you tell me how to write it
an f-string basically just formats the variables inside it into whatever you're working with
!e ```py
a = "hello"
b = "world"
print(f"{a} {b}")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
hello world
it automatically converts the variables into strings so you don't run into this issue
you can also use format specifiers (more advanced) like printing a number with comma separators ({x:,}), printing to 2 decimal places ({x:.2f}) and more
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
ok
you could also set the variable to a string total = str((price * int(number)))
no point
but f-strings are easier
if you wanted to add to the total, you'd have to turn it BACK into an integer, update the value, then make it a string again
i just wanted to give him another option
its good to know things like this
but yeah i agree with you
not a very good option
if you had an issue with a car that you needed to get to work that was 30 miles away, it wouldn't be a good idea to be recommended a bicycle
yeah but i just wanted to mention it
probably mention that it's also a bad idea
i said thats its easier to use f-strings
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.