raiprakashfca

Members
  • Content Count

    4
  • Joined

  • Last visited

  1. def add(num1, num2): """This function adds the value of arguments given to it. Only works with two arguments""" return num1 + num2 def sub(num1, num2): """This function substracts the value of arguments given to it""" return num2 - num1 def mul(num1, num2): """ This function multiplies the value of arguments given to it""" return num1 * num2 def div(num1, num2): """ This function divides the value of arguments given to it""" return num2 / num1 def main(): num1 = int(input("What is num1?")) num2 = int(input("What is num2?")) my_result1 = add(num1, num2) my_result2 = sub(num1, num2) my_result3 = mul(num1, num2) my_result4 = div(num1, num2) print(my_result1) print(my_result2) print(my_result3) print(my_result4) main() Edited my code. But still getting this error. C:\Python35\python.exe C:/Users/Dell/PycharmProjects/main.py/firststep.py What is num1?5 What is num2?5 Traceback (most recent call last): File "C:/Users/Dell/PycharmProjects/main.py/firststep.py", line 25, in <module> main() File "C:/Users/Dell/PycharmProjects/main.py/firststep.py", line 17, in main my_result2 = sub(num1, num2) File "C:/Users/Dell/PycharmProjects/main.py/firststep.py", line 6, in sub return num2 - num1 TypeError: unsupported operand type(s) for -: 'str' and 'str' Process finished with exit code 1
  2. Wow! Thanks a lot. Excited to hear from you. How can I convert this string to int? exactly at what stage should I do it?
  3. I wrote this piece of code for practice. I don't see what's wrong in it. Please help. def add(num1, num2): """This function adds the value of arguments given to it. Only works with two arguments""" return num1 + num2 def sub(num1, num2): """This function substracts the value of arguments given to it""" return num2 - num1 def mul(num1, num2): """ This function multiplies the value of arguments given to it""" return num1 * num2 def div(num1, num2): """ This function divides the value of arguments given to it""" return num2 / num1 def main(): num1 = input("What is num1?") num2 = input("What is num2?") my_result1 = add(num1, num2) my_result2 = sub(num1, num2) my_result3 = mul(num1, num2) my_result4 = div(num1, num2) print(my_result1) print(my_result2) print(my_result3) print(my_result4) main() This is the output that I am getting in debugger window - C:\Python35\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 63680 --file C:/Users/Dell/PycharmProjects/main.py/firststep.py pydev debugger: process 2028 is connecting Connected to pydev debugger (build 172.3317.103) What is num1?5 What is num2?10 Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\pydevd.py", line 1596, in <module> globals = debugger.run(setup['file'], None, None, is_module) File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\pydevd.py", line 1023, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/Dell/PycharmProjects/main.py/firststep.py", line 25, in <module> main() File "C:/Users/Dell/PycharmProjects/main.py/firststep.py", line 17, in main my_result2 = sub(num1, num2) File "C:/Users/Dell/PycharmProjects/main.py/firststep.py", line 6, in sub return num2 - num1 TypeError: unsupported operand type(s) for -: 'str' and 'str' Process finished with exit code 1