#๐Ÿ”’ Need help with a school question D:

16 messages ยท Page 1 of 1 (latest)

fervent elbow
#

My code:
Sum=1
fact=0
n= int(input("enter your number"))
x= int(input("enter your number"))
for number in range (2,n+1,2):
fact=1
for j in range (1,number+1):
fact=fact*j
k= x**number
Sum+= k/fact
print(Sum)

Would this code work and is it efficient for the question "1+(x^2/2!)+(x^4/4!)+....+(x^n/n!)" where x and n are user inputted values

plush riverBOT
#

@fervent elbow

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.

gritty obsidian
#

!code

plush riverBOT
#
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.

gritty obsidian
#

also, what is your code supposed to do?

#

hard to say if it will work or not without knowing what the intended effect is

safe eagle
#

Would this code work

is it efficient for the question "1+(x^2/2!)+(x^4/4!)+....+(x^n/n!)" where x and n are user inputted values

#

That's what I see

fervent elbow
#
fact=0
n= int(input("enter your number"))
x= int(input("enter your number"))
for number in range (2,n+1,2):
    fact=1
    for j in range (1,number+1):
        fact=fact*j
    k= x**number
    Sum+= k/fact
print(Sum)

sorry for messin' up

plush riverBOT
#

Hey @fervent elbow!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
fervent elbow
#

this is the code

#
Sum=1
fact=0
n= int(input("enter your number"))
x= int(input("enter your number"))
for number in range (2,n+1,2):
    fact=1
    for j in range (1,number+1):
        fact=fact*j
    k= x**number
    Sum+= k/fact
print(Sum)

the code is supposed to give the output of the equation "1+(x^2/2!)+(x^4/4!)+....+(x^n/n!)" where x and n are user inputted values

safe eagle
#

Is it powers of 2?

#
2, 4, 6, 8, 10

2, 4, 8, 16
plush riverBOT
#
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.