# Let's discuss some problem and lets try to solve this using python. Let's start very simple. lets consider a 3-deminsional vector. we need to give 3 components of the 3-dimensions. and let's calculate the magnitude of the vector
# Now lets, define the vector by entering the components of the vectors using the built-in function called input function in python
x = input("Enter x- compoent: "); #this would help us to enter the x-compoent of the vector
y = input("Enter y- compoent: "); #this would help us to enter the y-compoent of the vector
z = input("Enter z- compoent: "); #this would help us to enter the z-compoent of the vector
# after entering the compoents of the vectors we need to find the mod of the vector. but beofre that we have aproblem to solve to see that lets compile this once
Enter x- compoent: 2 Enter y- compoent: 3 Enter z- compoent: 4
x+y
'23'
#in the above line we have asked python to add x and y i.e. 2+3 which is 5 but instead of 5 we got 23. why? becasue x, y, and z values are taken as strings but not as nmber. to perform our operation we need to make them numbers.
#to do that I can use the varable float. let's do one for example
a=float(input("enter number: "))
enter number: 4
#now lets do some operation with the number we entered
a+4
8.0
# now lets calculate the modulus of the vector
r = (x**2+y**2+z**2)**0.5
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_2656\4104226498.py in <module> 1 # now lets calculate the modulus of the vector ----> 2 r = (x**2+y**2+z**2)**0.5 TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
# the above error occured because I forgot to take float on x, y, and z values.
#lets now write the entire code so that we could enter the desired values of the vector and find the modulus by clicking run once
x = float(input("Enter x- compoent: ")); #this would help us to enter the x-compoent of the vector
y = float(input("Enter y- compoent: ")); #this would help us to enter the y-compoent of the vector
z = float(input("Enter z- compoent: ")); #this would help us to enter the z-compoent of the vector
# now lets calculate the modulus of the vector
r = (x**2+y**2+z**2)**0.5
print("Modulus of the vector =",r)
Enter x- compoent: 1 Enter y- compoent: 2 Enter z- compoent: 3 Modulus of the vector = 3.7416573867739413
#python goes from line by line, but this is not the case we can execute some lines without going through some lines. Let's do that in the next example
t = float(input("Enter the temperature"))
if t>=100:
print("Water is in vapour state")
elif 0<t<100:
print("It is in liquid state")
elif t<=0:
print("It is in solid state")
Enter the temperature100 Water is in vapour state