#πŸ”’ (Repost) Program not accepted despite having info and giving the correct cost

35 messages Β· Page 1 of 1 (latest)

jolly nimbus
#

I have tried multiple ways to compute the total cost but it still isn't accepting my work.

Code:

Author: 

Compute the total cost of video rental.

1. Significant constants
       cost of new videos
       cost of oldies
       
2. The inputs are
       number of new videos
       number of new oldies
3. Computations:
       total cost = number of new videos * 3.00 + number of oldies * 2.00 

4. The outputs are
       the total cost
"""
# Request the inputs
a=int(input("Enter the number of new videos: "))
b=int(input("Enter the number of oldies: "))

# Compute the cost
New=  a*3.00
Oldies = b*2.00

#Display the total cost
print("The total cost is $",New+Oldies)```
steep shadowBOT
#

@jolly nimbus

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

amber merlin
#

ah, you could just have posted the new image later in the chat
anyways, lets continue

#

what have you learned in school so far when it comes to python?

jolly nimbus
#

Sorry I get really dumb when stressed

#

Nothing too informative
We get examples of codes and key words but not how to apply them and when to use them

amber merlin
amber merlin
jolly nimbus
#

Oh! I saw str in one of the pictures in my textbook
Didn't explain why or when to use it

earnest tundra
amber merlin
#

you are already doing something similar with the input() which always return (gives you) a string of text, but as you enclose it in int() you are trying to "cast" that string to an int (an integer, a whole number) if the string contains something that python thinks looks enough like an integer to be able to change it into that (or else you will get an error (in the form of an exception)

jolly nimbus
#

Omg it worked!!
I used
print("The total cost is $" + str(New+Oldies))

#

Do I just use this when calculating cost or is it needed for anything else?

amber merlin
#

this is called "explicit casting", there is also some "implicit casting" going on here, when you multiply the integer variable with a number that contains a decimal point (called a float) the answer will always be a float (so you get a decimal number back)

amber merlin
odd stone
amber merlin
#

and the plus in-between two strings becomes the "concatenation" operator

amber merlin
jolly nimbus
#

Not yet, but I'll keep it in mind!
If the course ever decides to be beginner friendly and mention it

#

Thank you all!

amber merlin
amber merlin
#

also, good job in solving the problem mostly on your own

odd stone
amber merlin
odd stone
jolly nimbus
amber merlin
amber merlin
jolly nimbus
#

Take care!

#

!close

steep shadowBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.