Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 days ago.
Improve this question
Theres a coupel list that form rectangels in a cordinat system.
One should get the total area from all of the rectangels.
(This is one part of a bigger funtion).
I think a have the formula down but can't get it to print out
def tvarsnitt(rektanglar):#uppgift: Beräkna z_tp, A, I_y
B = 0.10 #Basen
H = 0.15 #height
t = 0.010 #tjockleken på balkarna
liv = [0.0, 0.0, t, H] #Middel
fläns2 = [0.0, H/2+t/2, B, t] #over
fläns1= [0.0, -t/2-H/2, B, t] #under
rektanglar = np.array([fläns1, liv, fläns2])
def A(rektanglar):
total_area = 0
for room in rektanglar:
total_area += room[0] * room[1]
return total_area
A=total_area
print('Area:',A,'mm^2')
So I tried to put all of my list in an array. Sum the whole array and then print the result out. the first time i tried with
areas = (rektanglar[:,3] ) * (rektanglar[:,4]) #base* height
A=np.sum(areas)
return A
And the second time with def A(rektanglar):
But I'm not getting any results and don't understand where the probelm can be.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
The math.sine module seem to return wrong values. Where did I made a mistake ?
import math
A = float(input("Insert a number you want the sine of"))
B = math.sin(math.radians(A))
print("sin of %.2f is %.6f" % (A, B))
The result for typing 45 is 0.707 instead of 0.85
I was just getting back into Python. I can't see the error.
Be careful, there is difference between degrees and radians. You probably confused them with each other.
Calculate with radians:
import math
A = float(input("Insert a number you want the sine of"))
B = math.sin(math.radians(A))
print("sin of %.2f is %.6f" % (A, B))
Calculate with degrees:
import math
A = float(input("Insert a number you want the sine of"))
B = math.sin(math.degrees(A))
print("sin of %.2f is %.6f" % (A, B))
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have wrote this Code for calculates the product of the first natural numbers, but it showing answer 1 every time. I don't where i did mistake?? Can you please help me find out my mistake in this code..
num = 10
i = 0
prod = 1
while i<=num:
i = i+1
prod*prod*i
print(prod)
The problem seems to be on the line prod*prod*i. The product needs to be accumulated and for this it should be exchanged for prod*=i.
The new snippet is:
num = 10
i = 0
prod = 1
while i<=num:
print(i)
i = i+1
prod*=i
print(prod)
Instead of prod*prod*i write prod=prod*i
Here we first take the input of the number of terms.Then we iterate the for loop and multiply the value of x with the initial value(=1).Then we assign the new value to p.
n=int(input('Terms: ')) #specifing the limit
p=1
for x in range(1,n+1):
p=p*x
print(p)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying to write a weight converter which splits the given input and act accordingly however if statement is completely ignored. So far my search revealed that it might be a scope problem but I'm pretty green so couldn't apply any solutions to my specific code.
def weight_convert(answer):
seperated = answer.split(" ")
unit = seperated[1]
weight = int(seperated[0])
if unit.lower == "lbs":
converted = weight * 0.45
else:
converted = weight % 0.45
return converted, unit
Try this:
def weight_convert(answer):
seperated = answer.split(" ")
unit = seperated[1]
weight = int(seperated[0])
if unit.lower() == "lbs":
converted = weight * 0.45
else:
converted = weight % 0.45
return converted, unit
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to calculate percentage in Python, by hand this works fine but in python this formula for some reason does not work. I tried multiple ways but just not getting correct results.
getPercent = lambda part, whole: float(1 - (float(part)/float(part))) * 100
Val1= float(3194.15)
Val2= float(3163.84)
getPercent(Val2, Val1)
Output:
0.0
output should be:
0.95
Just use whole instead of part in the denominator.
getPercent = lambda part, whole: float(1 - (float(part)/float(whole))) * 100
Val1= float(3194.15)
Val2= float(3163.84)
getPercent(Val2, Val1)
Try it online!
you haven't used whole in your lambda function
getPercent = lambda part, whole: float(1 - (float(part)/float(whole))) * 100
Val1= float(3194.15)
Val2= float(3163.84)
getPercent(Val2, Val1)
# output 0.9489222484855064
You need to divide by whole. To get just two decimal places:
get_percent = lambda part, whole: float(1 - part / whole) * 100
val_1 = float(3194.15)
val_2 = float(3163.84)
a_float = get_percent(val_2, val_1)
print("{:.2f}".format(a_float))
Returning:
0.95
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
def vector(sample_list):
for item in sample_list:
sums = 0
square = item**2
sums = square + sums
magnitude = sums**0.5
return magnitude
print(vector([2,3,-4]))
Why this code doesn't give the correct magnitude?
It gives the last value of the vector in function call.
change sums=0 position
def vector(sample_list):
sums = 0
for item in sample_list:
square = item**2
sums = square + sums
magnitude = sums**0.5
return magnitude