Homework help please - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Homework help please (/thread-20955.html) |
Homework help please - EdensVoid - Sep-08-2019 # Input from the command line import sys A = sys.argv[1] B = sys.argv[2] C = sys.argv[3] # Your code goes here num = A * (B + C/3 # Outputs print ( numAlright, hi folks. I'm trying to finish my homework assignment and I've gotta do so: 4. 2. Fix challenge 2 Note: Your arguments are strings unless they are converted into some other type. In this challenge, we are using decimals (float) rather than integers (int) for our type. So, you will need to tell Python to treat the variables as floating point decimal numbers by putting float(variable) in at the correct times. I've tried print(float(num))and even num = (float(A*(B+C/3))but I get: "Traceback (most recent call last): File "fix2.py", line 9, in num = A * (B + C/3) TypeError: unsupported operand type(s) for /: 'str' and 'int'" What am I doing wrong? RE: Homework help please - HurryHome - Sep-08-2019 You can use num = float(A) * (float(B) + float(C)/3) RE: Homework help please - ichabod801 - Sep-08-2019 Or you can do it when you first read the value: A = float(sys.argv[1]) .
|