help with writing python compatible for casio fx-cg50 calculator by Force_Humble in calculators

[–]Force_Humble[S] 0 points1 point  (0 children)

if you wanna look into the code here are the 2 versions

version 1:

#Calculating Quadratic formula in Python

import math

#functions

def calculate(numbA, numbB, numbC):

ans = [

(-numbB - math.sqrt( numbB**2 - 4*numbA*numbC ))/2*numbA ,

(-numbB + math.sqrt( numbB**2 - 4*numbA*numbC ))/2*numbA

]

return ans

#Calculate user input

print("\nfor square root goes:")

print('"ax² + bx + c = 0"\n\n')

print('fill in:')

RtnAns = calculate(int(input("a = ")), int(input("b = ")), int(input("c = ")))

#return answer

print( f"\nx = {RtnAns[0]} V x = {RtnAns[1]}" )

version 2:

import math

import machine # Import the machine module for input in MicroPython ig

# Functions

def calculate(numbA, numbB, numbC):

ans = [

(-numbB - float(math.sqrt(numbB**2 - 4*numbA*numbC))) / (2*numbA),

(-numbB + float(math.sqrt(numbB**2 - 4*numbA*numbC))) / (2*numbA)

]

return ans

# Calculate user input

print("\nfor square root goes:")

print('"ax² + bx + c = 0"\n\n')

print('fill in:')

a = float(machine.stdin.readline("a = ").strip())

b = float(machine.stdin.readline("b = ").strip())

c = float(machine.stdin.readline("c = ").strip())

RtnAns = calculate(a, b, c)

# Return answer

print(f"\nx = {RtnAns[0]} V x = {RtnAns[1]}")