Python Forum
Why am I getting this error?? Help me out!!! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Why am I getting this error?? Help me out!!! (/thread-14590.html)



Why am I getting this error?? Help me out!!! - ghustcat590 - Dec-08-2018

from sys import argv
script, number1, number2 = argv


print("Here is your 1st number: ", number1)
print("Here is your 2nd number: ", number2)
product = number1 * number2
print(f"Here is your product: {product}")
number3 = int(input("Enter your number: "))
last_ans = number3 * product
print(f"Here is your final product times {number3}: ", last_ans)
I am a beginner in Python..


RE: Why am I getting this error?? Help me out!!! - Gribouillis - Dec-08-2018

Without the error message, it is difficult to answer. The first thing I see is that sys.argv contains character strings, not numbers. If you want to use them as numbers, you need to convert them first, for example
>>> int("32")
32
>>> float("32")
32.0



RE: Why am I getting this error?? Help me out!!! - jeanMichelBain - Dec-08-2018

Please say also the python version.
It's important because, for instance, the format string used in your code does not work with python < 3.6.
For those using 3.5 (as provided in debian) this is the working code
from sys import argv
script, number1, number2 = argv
# see the previous reply 
number1 = int(number1)
number2 = float(number2)
#
print("Here is your 1st number: ", number1)
print("Here is your 2nd number: ", number2)
product = number1 * number2
#~ print(f"Here is your product: {product}")
print("Here is your product: {}".format(product))
number3 = int(input("Enter your number: "))
last_ans = number3 * product
#~ print(f"Here is your final product times {number3}: ", last_ans)
print("Here is your final product times {}: ".format(last_ans))