Create a string called product


#1

Hey guys, so in one of the lessons it says “Create a string called product that contains the result of multiplying the float value of float_1 and float_2.”, and then I found out the correct answer is product = float_1 * float_2. I thought that strings relied on having quotes, is that not true?


FAQ: Learn Python - Python Syntax - ValueError
#2

https://www.codecademy.com/courses/learn-python/lessons/python-syntax/exercises/value-error?action=resume_content_item

I was okay with the first instruction, I can’t figure out the second one. The language is not great, but I still feel like I should be able to get it.

Create a string called big_string that says:

The product was X
with the value of product where the X is.

What?
Please help!
I’m also done here!

I tried a few things, including creating another variable for product, just don’t have enough information.

big_string = x
print "The product was " + str(product)

Tell me tell me tell me


#3

Try defining big_string in its entirety then print it.

big_string = ...

print big_string

#4

yeah, i don’t know man …

need more information
and the more syntax i/we can learn the more we can figure out ways to do things.
this is the first interactive lesson …


#5

There is the complete string. Just assign it to the variable (without the print keyword.


#6

I understand the exercises in these interactive lessons are cumulative in that the early instructions tell you exactly what to do (or close to it) and gradually you have to follow the pattern and figure things out.
I’ve had a lot of trouble with 13/14. Can anyone provide more information and shed some light on the objective and what the code is meant to do?
Or, can you suggest where to look for such information in addition to this forum?

I was able to proceed with the code:

big_string = "The product was " + str(product) + “x”
print "The product was " + str(product)

… which doesn’t even seem like it should be right to me.
Sometimes in coding – and I am a total beginner – you don’t really have to know “why” if you are reasonably certain it will work. Here I would really like to know why.

Perhaps that’s vague, but I’m just looking for more information to understand these operations.


#7

There is an error in this problem

The instructions say that we should create a string called product, which contains the float value of the product of float_1 and float_2

The correct solution is actually to create a float called product which contains that value.


#8

The instruction is a little convaluted. I interpreted it thus…

float_1 = 40.0
float_2 = 0.25

product = float_1 * float_2
big_number = "The product was " + str(product)

print big_number

#9

This would have been easier to figure out if we knew to 1. “not solve for X” (I wasted time trying to assign a variable of X = product… which was not the intended question.) 2. We were given the clue that we would be reassigning a float, or integer, into a ‘string’ which included the ‘product’ as a number.


#10

#Define the product from the value you got from the first equation.
product = 10
#create the string called big_string. with the value of the product where x is
big_string = "The product was " + str(product)
Print(big_string)


#11

I’m having the exact same confusion. I thought strings were contained inside of “”. I really wish This website was a bit more intuitive for the uber beginners like me. Some of the word choice is so bad, It really makes the learning tedious.


#12

What you are being asked to do here is create a string that fills in the missing information. Take this as an example:

product = 6

big_string = "The product was " + str(product)

print big_string

It is having you practice concatenation using str() to convert an integer into something that can be printed as a string object.


#13

I felt the instructions for ‘Create a string called product…’ are misleading. When you press the ‘run’ button, Codecademy is looking for a float. So the instructions should say ‘Create a value called product’ or ‘Create a variable called product.’ I had this wrong because I was doing str(float_1*float_2), and after I removed the string conversion my answer was accepted.


#14

I also seem to be lost in 13/14 because I also thought strings are always in quotations.I got stuck and generated the solution and once I did, the solution was exactly the same as what I had typed before which was being rejected quoting that my solution was giving a float value of 10 when it should just be 10!!But whatI wrote and what they gave me was the same thing!
float_1 =0.25
float_2 = 40.0
product = float_1 * float_2

big_string = "The product was " + str(product)
print big_string

I still think that exercise has a problem and should be reviewed


#15

Yes, I had a similar issue , the solution to the code still prints a float when the instructions ask for an int. Additionally I did get it to print an int but every time I try to contain a print statement in a variable “big_string” it returns an error. I am sure this comes down to my lack of knowledge/ability but I think this exercise may require review. Thank you , this is a very helpful tool.

EDIT: the reason I was unable to create the variable is because I was adding print to the statement which created a syntax error rather

string = “this is a string” + str(variable) would work. The solution code would return a float though


#16

Here is the correct code but I am sure there are multiple ways of getting this one correct:

float_1=2.
float_2=5.

product = float_1*float_2

One thing they failed to say in the instructions is that they want the product to be equal to 10 so pick any 2 floats (decimals) that will equal 10.