Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error?
#4
(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'))
Reply


Messages In This Thread
Error? - by juliabrushett - Jul-02-2018, 03:07 AM
RE: Error? - by Zombie_Programming - Jul-02-2018, 03:51 AM
RE: Error? - by gruntfutuk - Jul-02-2018, 11:43 AM
RE: Error? - by Zombie_Programming - Jul-03-2018, 02:49 AM
RE: Error? - by buran - Jul-03-2018, 04:14 AM
RE: Error? - by Zombie_Programming - Jul-03-2018, 05:43 AM
RE: Error? - by buran - Jul-03-2018, 06:01 AM
RE: Error? - by Zombie_Programming - Jul-03-2018, 06:18 AM
RE: Error? - by gruntfutuk - Jul-03-2018, 11:22 AM
RE: Error? - by buran - Jul-03-2018, 06:23 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020