Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework help please
#1
# 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 ( num 
Alright, 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?
Reply
#2
You can use
num = float(A) * (float(B) + float(C)/3)
Reply
#3
Or you can do it when you first read the value: A = float(sys.argv[1]).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

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