Cannot find my error again!


#1

I am in a beginners class so i dont know the advanced things. Can someone tell me what my error/s are? nothing shows in the output


#2

#3/3/18
#Purpose:To find the total, sub total and tax of all of the items in the wish list
#Numeric input
def main():
unoVar = int(input(“What is the cost of the first value?”))
unoVar2 =int(input(“What is the cost of the second value?”))
unoVar3 = int(input(“What is the value of the third value?”))
print(“Time to shop on amazon!”)
print(“Your order:”)
print(“Item Cost”)
print(“COD BO2 $” + unoVar + “.”)
print(“Xbox one $” + unoVar2 + “.”)
print(“Lamp $” + unoVar3 + “.”)
print("---------------------------------------------------")
subtotal = unoVar + unoVar2 + unoVar3
tax = subtotal * 0.07
shipping = 5.99
order_total = tax + subtotal + shipping
print(" Subtotal: $"+ subtotal + “.”)
print(" Tax: $"+ tax + “.”)
print(" Shipping: $" + shipping + “.”)
print(" Order total: $"+ order_total + “.”)

main()

#3

without proper code formatting i.e.

def main():
  some_variable = 'test'
  some_variable_also = 'test 2'
  print some_variable

main()  

it is hard to tell what your errors could be, as formatting is just as important as syntax.

from looking into your code, I see one error for sure;

this will not execute because you are trying to do what is called ‘concatenating a string’ which basically means putting more into it than just text. now there is a way to do what you are attempting, I don’t know, however, if you have learned of this yet in Codecademy’s lesson.

you can try two things to get this to work:

(Easier version)
For the easier method, you would want to write the following:

print("COD BO2 $" + str(unoVar) + ".")

the str() around your unoVar is what is called the string method. this is converting your unoVar which is currently an int() or integer (im sure you know this because you used the int method) into a string, and so now, when you pass the above code, it will be writing everything as a string, and thus will work.

# ---

(Moderate version)
Something that looks a little bit cleaner, and I feel is faster and easier to use once you get the hang of it, is called Modulo. Modulo makes use of the ‘%’ as what you could call a value placeholder, and as such, allows you to pass values in with it. Here is the example:

# you are fine using double quotes, i just like to use single
cod_var = 'COD BO2'
unoVar = int(input('What is the cost of the first value? '))
# passing 10 as the value for variable unoVar
print (('%s $%s.') % (cod_var, unoVar))
# Output:
>> COD BO2 $10.

now as I said previously, you are using the ‘%s’ to act as a place holder for you to later pass it a value using ‘modulo’ or ‘%’

this concept applies to a lot of what you have written here, so take note of what I have said, try it out, and let me know if you need any more help!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.