#πŸ”’ Python runtime error

30 messages Β· Page 1 of 1 (latest)

potent berry
#

My code is runtime error. Help me fix that

import numpy as np

def sigma_mod(n):
if n==1:
return 0
result = 0
for i in range(1, n):
for j in range(1, n + i):
s = i + j
if n + s < 1000:
k = np.arange(1, n + s, dtype=np.int64)
denom = i + j + k
safe_denom = np.where(denom == 0, 1, denom)
mod_vals = (i * j * k) % safe_denom
result += np.sum(mod_vals)
else:
for k in range(1, n + s):
denom = s + k
if denom != 0:
result += (i * j * k) % denom
return result

if name == "main":
n = int(input())
if n > 0:
numbers = []
for i in range(n):
num = int(input())
if num >= 0:
numbers.append(num)
else:
break
results = [sigma_mod(num) for num in numbers]
for result in results:
print(result)

dusty riverBOT
#

@potent berry

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.

quartz gorge
#

what is the error exactly ?

#

also

#

!codeblocks

dusty 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.

potent berry
#

What is it?

quartz gorge
#

that's to make code more readble on discord

potent berry
#

Oh

#

That great

#

Should I click Pastebin?

quartz gorge
#
print('Hello world!')

use this

#

the ` ` ` thing

#

(or yes use the pastebin that's fine)

potent berry
#

print(’test’)

quartz gorge
#

use backticks `

#

(copy paste from the bot message and replace the code)

potent berry
#
import numpy as np

def sigma_mod(n):
    if n==1:
        return 0
    result = 0
    for i in range(1, n):
        for j in range(1, n + i):
            s = i + j
            if n + s < 1000:
                k = np.arange(1, n + s, dtype=np.int64)
                denom = i + j + k
                safe_denom = np.where(denom == 0, 1, denom)
                mod_vals = (i * j * k) % safe_denom
                result += np.sum(mod_vals)
            else:
                for k in range(1, n + s):
                    denom = s + k
                    if denom != 0:
                        result += (i * j * k) % denom
    return result

if __name__ == "__main__":
    n = int(input())
    if n > 0:
        numbers = []
        for i in range(n):
            num = int(input())
            if num >= 0:
                numbers.append(num)
            else:
                break
        results = [sigma_mod(num) for num in numbers]
        for result in results:
            print(result)
#

is that right?

quartz gorge
#

what is the error ?

boreal edge
#

It is running just fine, can you provide the testcase on which it is failing?

potent berry
#

I submit to some coding practices website and show the runtime error. I don't know as well that why the runtime error

#

And the maximum number of inputs is 199

boreal edge
#

Think of edgecases, dry run it and see what's wrong

#

btw if you are submitting on codeforces, then you can check exactly where the issue is occuring

potent berry
#

I have submitted 199 on this code, it has waited for a bit, and shows the output

dusty 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.