KGB
(dash free)
March 7, 2024, 12:37pm
1
import random
height = [2, 2.34, 3, 3.45, 4, 6, 10.2]
width = [15, 100, 6.67, 3.99, 5.67, 2.67, 200]
select a program that removes 2 values from this list
random_height = random.sample(height, 1)
random_width = random.sample(width, 1)
convert into square meters
square_meters = random_height * random_width
divide by the total area of the paint
paint_quantity = square_meters / 2
print(f’With a wall of {random_height:.2f} height x {random_width:.2f} width\nYou will need {quantity_paint:.2f} of paint buckets.')
answer
TypeError: can’t multiply sequence by non-int of type ‘list’
If you ask me what’s wrong I don’t know how to answer. I’ve been learning programming for 7 days and I barely know what I’m doing
abessman
(Alexander Bessman)
March 7, 2024, 12:39pm
2
Please read the pinned topic and follow the instructions to format your code properly.
3 Likes
KGB
(dash free)
March 7, 2024, 12:50pm
4
can you give me the link name?
kknechtel
(Karl Knechtel)
March 7, 2024, 1:03pm
5
Where the code says
Did you try to check what random_height
looks like after that?
What do you think should be in random_height
after that?
When you check it, is it as you expect?
What does the documentation tell you about random.sample
?
2 Likes
KGB
(dash free)
March 7, 2024, 2:28pm
7
ok my friend, I already corrected what you helped me with. But now I’m having a new problem at 1 hour I can’t solve it:
msg error:
88, in
square_meters = new_height * new_width
~^ ~~~~
TypeError: unsupported operand type(s) for *: ‘NoneType’ and ‘NoneType’
KGB
(dash free)
March 7, 2024, 2:32pm
8
the code looked like this
import random
height = [2, 2.34, 3, 3.45, 4, 6, 10.2]
width = [15, 100, 6.67, 3.99, 5.67, 2.67, 200]
#random heights
new_height = print(random.sample(height, 1))
new_width = print(random.sample(width, 1))
convert into square meters
square_meters = new_height * new_width
total ink
paint_quantity = square_meters / 2
print(f’Wall is a wall of {square_meters}\nYou will need {quantity_paint:.2f} of paint cans.')
Rolando
(Rolando)
March 7, 2024, 3:46pm
9
You need to look carefully at the code that you write. There are three errors here. I will give you a couple of clues of where to look:
The first is that quantity_paint is not the same as paint_quantity.
The second is that in your code random_height
and random_width
are not numbers but lists with one item. You need to change this.
your statement
print(f’Wall is a wall of {square_meters}\nYou will need {quantity_paint:.2f} of paint cans.')
has the wrong type of " ' " enclosing it. This may just be because you have not formatted your code properly here in the forum.
It should look like:
print(f'Wall is a wall of {square_meters}\nYou will need {quantity_paint:.2f} of paint cans.')
Finally please follow @Kknechtel advice - read the documentation on the random.sample
function to understand how it works.
I hope this helps you solve your problems.