There is 2 ways to concatenate integer with string in python:
#(1) print(“The number of square needed”, number_of_squares)
adding a comma in between the variable and the string will allow you concatenate them with out error
#(2)
adding a f {short cut for formate} at the beginning of the sentence out side of the paretics like this
print(f"The number of square needed {number_of_squares}")
In a different python course, it said the last line of code was automatically outputted without having to use a print() statement. Why is that not the case in this excercise?
I have trouble understanding the context. The 1st task says, " To calculate the number of squares you’ll need for your first quilt let’s create two variables: quilt_width and quilt_length . Let’s make this first quilt 8 squares wide and 12 squares long."
Although the answer is the product of the two, but, doesn’t it tell us the area of the quilt? If we know the area of each individual squares, then the number of squares can easily be found out by dividing the former by the latter, right? Can anyone tell me what point I’m missing?
I don’t think the exercise uses a specific system of measurement so you’re just relying on the standard area = width * length for a rectangle. You could say you’re using ‘squares’ as your unit (instead of square centimetre, square foot etc.) if that reads a little better to you.
Oh! So, the number of squares is not the actual square shapes in the quilt, but rather the square ‘units’ (from the product of length and width)? I got confused by the usual image of a quilt having different square fabrics. Thank you.
On the changing numbers lesson. I assign two separate values to two separate variables
variable_1 = 5
variable_2 = 10
I assign the product of these two variables to a newly declared variable
variable_product = variable_1 * variable_2
I print variable_product and get the proper output (in this case 50).
I update variable_2 to 5 two lines below the print(variable_product) string I just processed.
#prints 50
print(variable_product)
variable_2 = 5
I print variable_2 to see if the update worked and it prints 5.
I reprint the variable_product but instead of outputting the value 25 it maintains its old output (50) in which case variable_2 = 10 and not the newly updated 5.
What am I doing wrong?
If I rewrite variable_product = variable_1 * variable_2 on the line above the second print(variable_product) then it outputs 25, but I can see how that would be counter-productive at times. Thank you for any help in advance.
Maybe I’m jumping the gun and assuming this works like JS.
More generally you could have a web search for how python passes objects around, something like the following may help but there’s quite a lot of discussion on it around the web-
Silly or laziness question. Wouldn’t be easier or practical to just change the quilt_length number from “12” to “8” to satisfy intrusction #3, instead of adding additional lines as it shows in the walkthrough video?