#๐Ÿ”’ Python calculator

56 messages ยท Page 1 of 1 (latest)

bitter citrus
#

I'm trying to make a python calculator that takes a factorial of a number, adds it to a list, then does it for the number below it, again and again all the way down to zero. I think I have the code right for the calculation but I cant get it to add to the list

I'm not sure if I should be using yield, or append to add the int to the list. I am very new to coding and I made this completely on my own so maybe use more basic wording

        num1 = int(input("enter number to be factorialized "))
        numf = 1
        t = num1
        c=5
        for i in range(c):
            for i in range(t):
                numf *= (num1)
                num1 -= 1
            factoriallist.append(numf)
            t -= 1
        print(resulter)
        resulter = list(factoriallist(numf))

factoriallist()'''
spark canyonBOT
#

@bitter citrus

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.

river wharf
#

wait wait wait can you explain a lil more about what you are trying to do

lusty lintel
bitter citrus
#

I want to calculate the factorial of a number, then calculate the factorial of the number below it until it reaches zero

#

I coded my own factorial function because i didnt want to use math.py

versed timber
#

I am trying ti make this thing but only for addition but irs bugging and I got the answer as 12 fkr 1 + 2

lusty lintel
#

@versed timber Please open your own thread

lusty lintel
bitter citrus
#

I just wanna know to add my number I calculate to the list

#

I just dont know how to add to the list

versed timber
#

I never said I wanted help

lusty lintel
lusty lintel
bitter citrus
#

it gives an error, its like append cant add an int

lusty lintel
#

Oh, factoriallist is the function. You never actually create a list here anywhere.

#

You want something like factorials = [], then you append to that.

bitter citrus
#

oh okay

#

thank you

#

I get it

#

i thought it was

lusty lintel
#

Also here:

print(resulter)
resulter = list(factoriallist(numf))

Note how you try to print resulter before you assign it.

#

That will be another error.

bitter citrus
#

i fixed that after i posted the thread

#

it says list is not callable now though

lusty lintel
#

Also, you should probably get rid of those lines anyway, since it's weird to make it recursive.

lusty lintel
bitter citrus
#

list' object is not callable

lusty lintel
#

And what's the traceback? You're omitting a lot of the error message.

bitter citrus
#
        factoriallists = []
        num1 = int(input("enter number to be factorialized "))
        numf = 1
        t = num1
        c=5
        for i in range(c):
            for i in range(t):
                numf *= (num1)
                num1 -= 1
            factoriallists.append(numf)
            t -= 1
        resulter = list(factoriallists(numf))
        print(resulter)

factoriallist()
spark canyonBOT
#

Hey @bitter citrus!

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.
lusty lintel
#

factoriallists(numf).

#

Note the name there

#

s

bitter citrus
#

the error is on ``` resulter = list(factoriallists(numf))

lusty lintel
#

Like I mentioned though, you should get rid of those lines. I don't see why you're trying top recursivley call the function.

lusty lintel
#

You're calling the list, not the function.

#

Again, note the name. You made the list almost the same name as the function, then mixed them up.

bitter citrus
#

i know the name sucks

#

i just dont know which one to put there though

lusty lintel
#

The name of the function

#

Presumably

bitter citrus
#

so like this ``` resulter = list(factoriallist(numf))

lusty lintel
#

Yes, but that will just cause another error because your function doesn't take an argument

bitter citrus
#

how do I fix that error

lusty lintel
#

What are you trying to do with that line?

bitter citrus
#

define resulter so I can print it on the next lien

lusty lintel
#

But why list(factoriallist(numf))?

#

Wait, do you mean factoriallists[numf]?

#

() is for calling functions. [] is for indexing lists.

#

(among other uses)

bitter citrus
#

wait i changed some things and I figured it out

#

i got it working

spark canyonBOT
#
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.