Jul-03-2018, 02:49 AM
(Jul-02-2018, 11:43 AM)gruntfutuk Wrote: Using eval() on user input is a really bad thing. A user could enter code, for example, to delete all the files on your drive!
I understand the consequences of using eval, I was simply trying to produce an example for the person to go off of. You could also get a and b in different input statements, like below.
import math def pythag( a, b, c1): if(c1 == 'c') : c = math.sqrt(pow(a, 2) + math.pow(b, 2)) else : c = math.sqrt(pow(a,2) - math.pow(b,2)) return c a = float(input("Pythagorean theorem, Enter side A")) b = float(input("Enter side B and I will solve for C\n")) print("Side C is equal to", pythag(a, b,'c')) a = float(input("Pythagorean theorem, Enter side B")) b = float(input("Enter side C and I will solve for A\n")) print("Side A is equal to", pythag(b, a,'a')) a = float(input("Pythagorean theorem, Enter side A")) b = float(input("Enter side C and I will solve for B\n")) print("Side B is equal to", pythag(b, a,'b'))