Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error?
#2
A way to solve this is to get rid of the ipt.split(" ") and change your int(input(...)) to eval(input(...)) like I do here,

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,b = eval(input("Pythagorean theorem, Enter sides A and B and I will solve for C\n"))
print("Side C is equal to", pythag(a, b,'c'))
 
a,b = eval(input("\nNow enter sides B and C and i will solve for A\n")) 
print("Side A is equal to", pythag(b, a,'a'))
 
a,b = eval(input("\nFinally, enter sides A and C and i will solve for B\n"))
print("Side B is equal to", pythag(b, a,'b'))

Here's the output:
Output:
Pythagorean theorem, Enter sides A and B and I will solve for C 3,4 Side C is equal to 5.0 Now enter sides B and C and i will solve for A 4,5 Side A is equal to 3.0 Finally, enter sides A and C and i will solve for B 3,5 Side B is equal to 4.0

Also, while I'm still here, you should place your error in error tags, along with the entire error. Like this
Error:
Traceback (most recent call last): File "C:/Users/bagpi/Desktop/test.py", line 12, in <module> ipt = int(input("Pythagorean theorem, Enter sides A and B and I will solve for C\n")) ValueError: invalid literal for int() with base 10: '1 2'
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