diff --git a/eval.py b/eval.py new file mode 100644 index 0000000000000000000000000000000000000000..eca9283563f477a8a5b0039250ce7d135a09f89a --- /dev/null +++ b/eval.py @@ -0,0 +1,49 @@ +import os +import math + +def volume(r): + if r <= 0: + return "The ray you have entered must be different from 0 and positive!" + return (4*math.pi*r**3)/3 + +def read_result(fileName="result.txt"): + script_dir = os.path.dirname(os.path.abspath(__file__)) + filePath = os.path.join(script_dir, fileName) + with open(filePath, 'r') as file: + content = file.read() + return float(content) + +def save_result(volume, fileName="result.txt"): + script_dir = os.path.dirname(os.path.abspath(__file__)) + filePath = os.path.join(script_dir, fileName) + with open(filePath, 'w') as file: + file.write(str(volume)) + +def htmlPage(result): + htmlContent = f""" + <!DOCTYPE html> + <html> + <head> + <title>Sphere volume</title> + </head> + <body> + <h1>Volume : {result}</h1> + </body> + </html> + """ + with open("resultat.html", 'w') as htmlFile: + htmlFile.write(htmlContent) + +def main(): + r = float(input("Ray: ")) + resultat = volume(r) + print("Volume: ", resultat) + + # Saving the result in a txt file + save_result(resultat) + + # Creating the HTML page + htmlPage(resultat) + +if __name__ == "__main__": + main()