Python Forum
Why am I getting this error?? Help me out!!!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why am I getting this error?? Help me out!!!
#1
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..
Reply
#2
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
Reply
#3
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))
Reply


Forum Jump:

User Panel Messages

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