gugtenterf Posted February 6 Report Share Posted February 6 Question- TaskThe provided code stub reads two integers from STDIN, and . Add code to print three lines where: The first line contains the sum of the two numbers. The second line contains the difference of the two numbers (first - second). The third line contains the product of the two numbers. Example Print the following: 8 -2 15 my answer if __name__=='__main__': a=input(int()) b=input(int()) if 1<=a<=10**10 and 1<=b<=10**10: summation = a+b diff = a-b multiply = a*b print(summation) print(diff) print(multiply) error Traceback (most recent call last): File "Solution.py", line 6, in <module> if 1<=a<=10**10 and 1<=b<=10**10: TypeError: '<=' not supported between instances of 'int' and 'str' Quote Link to comment Share on other sites More sharing options...
gugtenterf Posted February 6 Author Report Share Posted February 6 (edited) 3 minutes ago, gugtenterf said: Question- TaskThe provided code stub reads two integers from STDIN, and . Add code to print three lines where: The first line contains the sum of the two numbers. The second line contains the difference of the two numbers (first - second). The third line contains the product of the two numbers. Example Print the following: 8 -2 15 my answer if __name__=='__main__': a=input(int()) b=input(int()) if 1<=a<=10**10 and 1<=b<=10**10: summation = a+b diff = a-b multiply = a*b print(summation) print(diff) print(multiply) error Traceback (most recent call last): File "Solution.py", line 6, in <module> if 1<=a<=10**10 and 1<=b<=10**10: TypeError: '<=' not supported between instances of 'int' and 'str' https://pythondev.online/ thanks in advance for any help Edited February 6 by gugtenterf Quote Link to comment Share on other sites More sharing options...
rallan_md_3311 Posted March 30 Report Share Posted March 30 a = [4,5,6] b = [1,2,3] answer_list = [(x[0]+x[1],x[0]-x[1], x[0]*x[1]) for x in zip(a,b)] for answer in answer_list: print("add",answer[0]) print("subtract",answer[1]) print("product", answer[2]) print() ************************ add 5 subtract 3 product 4 add 7 subtract 3 product 10 add 9 subtract 3 product 18 Quote Link to comment Share on other sites More sharing options...
rallan_md_3311 Posted March 30 Report Share Posted March 30 with numpy: ********************************** import numpy as np arr1 = np.array(range(1,4)) # [1,2,3] arr2 = np.array(range(4,7)) # [4,5,6] add_arr = arr2 + arr1 print("sums",add_arr) sub_arr = arr2 - arr1 print("differences",sub_arr) multi_arr = arr2 * arr1 print("products",multi_arr) *************************** sums [5 7 9] differences [3 3 3] products [ 4 10 18] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.