# math

## How do you calculate the amount of prime numbers less than or equal to N?

How do you calculate the amount of prime numbers less than or equal to N? Question: I want to write a program that determines the amount of prime numbers less than or equal to N (variable containing user input). This is what I’ve got: N = int(input("Enter number: ")) count = 0 primes = [] …

## Variable returns empty even when assigned by dictionary – Python

Variable returns empty even when assigned by dictionary – Python Question: When crying to convert an RGB value to Hex using dictionaries one variable returns correctly as the Key turned to the Hex value but when tried with a second variable it returns as None. capitalization doesnt seem to be the problem. def rgb(r, g, …

## How to find the biggest possible combination of two numbers under a certain threshold from a list?

How to find the biggest possible combination of two numbers under a certain threshold from a list? Question: So let’s say if the list is [2,5,14,18,44], what I want to find out is what the biggest sum of two numbers under 60 would be. So the correct answer should be (14,44) Right now I am …

## Parametric curve is always in front of Surface

Parametric curve is always in front of Surface Question: I am trying to build an animation of a Dehn twist in a torus in Manim. My goal is to get something that looks like this: I managed to parametrize the curve and surface correctly in Manim. As you can see, the portion of the parametric …

## Float division issue in Python (tkinter)

Float division issue in Python (tkinter) Question: I’m working on a program which uses inputs from a tkinter interface to calculate the relative funniness of a joke based on sciencewritenow.com’s formula: H ≥ ((((T1 + T2) / (T3 – R)) × I ) / D = ((T3 / T4) × S)) × B While I …

## Sympy yields `TypeError: unsupported operand type(s) for *: 'interval' and 'complex'` for complex rational expression

Sympy yields `TypeError: unsupported operand type(s) for *: 'interval' and 'complex'` for complex rational expression Question: I have this sympy script: from sympy import * from sympy.plotting import plot_implicit x, y = symbols(‘x y’, real=True) alpha = sqrt(2) / 2 expr = 1 + ((1-alpha) * x + y*I) / (1 – alpha * (x …

## Octal to Decimal conversion of number

Octal to Decimal conversion of number Question: I want to convert an octal number into a decimal one. Why am I getting 6 as an output instead of 83? import math def octalToDecimal(octalNumber): decimalNumber = 0 i = 0 while (math.floor(octalNumber) != 0): rem = math.floor(octalNumber) % 10 octalNumber /= 10 decimalNumber += rem * …

## Is there an efficient way to determine if a sum of floats will be order invariant?

Is there an efficient way to determine if a sum of floats will be order invariant? Question: Due to precision limitations in floating point numbers, the order in which numbers are summed can affect the result. >>> 0.3 + 0.4 + 2.8 3.5 >>> 2.8 + 0.4 + 0.3 3.4999999999999996 This small error can become …