#πŸ”’ Digit calculation

45 messages Β· Page 1 of 1 (latest)

calm bloom
#

How can I interact with this file and calculate the amount of digits, while also excluding the commas?

dawn garnetBOT
#

@calm bloom

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.

dawn garnetBOT
jagged abyss
#

you could remove the commas and then get the length of the string

restive jungle
#

!e

print(len("80,995,899".replace(",", "")))
dawn garnetBOT
restive jungle
#

e.g.

calm bloom
#

Right now the file looks like this.

#

How do I even calculate it?

#

Like where do I write the code.

restive jungle
#

uh

#

in a file?

#

have you ever used python before?

calm bloom
#

Yes

#

But

restive jungle
#

well then

calm bloom
#

I'm not too well with

#

text files

#

This is read only

restive jungle
#

you need to read the text file into a string.

calm bloom
restive jungle
#

e.g

#
>>> with open("/var/folders/b0/_p0c_57s5n90cy4njdgd8vhw0000gq/T/x/message.txt") as inf:
...   numbers = inf.read()
...   print(len(numbers.replace(",", "")))
... 
10
calm bloom
#

hmmm yeah, I figured we'd need to use open here.

#

Okay one moment.

#

Do I need to import anything, btw?

restive jungle
#

no

calm bloom
#

okay.

restive jungle
#

this is homework, isn't it

calm bloom
#

Nope.

#

My friend just randomly told me

#

"Go calculate this" πŸ’€

thorn marten
#

how much python u know pithink

calm bloom
#

Well uh

#

I made a rock paper scissors bot

#

with

#

well not bot

#

just code

#

2 real people playing it.

#

That's probably my biggest achievement so far.

#

Okay it worked.

#

Thanks!

#

!close

dawn garnetBOT
#
Python help channel closed with !close

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.