From d04e3f53fdce882ac26a5b1fd117c767340aae97 Mon Sep 17 00:00:00 2001 From: RENAUX Anna <anna.renaux5@etu.univ-lorraine.fr> Date: Wed, 10 Jan 2024 10:56:50 +0000 Subject: [PATCH] Upload New File --- eval.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 eval.py diff --git a/eval.py b/eval.py new file mode 100644 index 0000000..c34b0d4 --- /dev/null +++ b/eval.py @@ -0,0 +1,47 @@ +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) + -- GitLab