User input:
It is the most important feature for every software language where a user can input s
and the software or function return a value.
For example we have calculated height of an object at time 0.2s with initial velocity
m/s and g = 9.81 m/s2. But I have an wish to find out the height at any time I want.
should I do?
If the process of changing value of the time and write the whole program again and ag
better to quit the use of python and seek for other language.
No, I don’t give this opportunity to you.
There is a command ‘input()’ which serve the purpose.
But we have to follow the steps.
i) Goto start menu and find IDLE Shell 3.9.7 for Python 3.9.7 version and run the programme.
ii) Go to file and select new file and save it with a name.
iii) Right click on the file and select edit with IDEL
iv) Delete all the written words and start freshly your program.
,Exercise- Find out height of an object at a given time and initial speed.
# user input for morethan one variable
Ans.
u= input('initial speed in m/s ')
u=float(input('initial speed = ')) g=9.81
a = input ('acceleration in m/s^2 ')
t=float(input('enter the time ')) h=u*t -
0.5*g*t*t # type conversion is necessary t= input ('time in s ')
for run the program. v=u+a*t
print('height at time %1.2f s is %2.2f Traceback (most recent call last):
m'%(t,h))
File "<pyshell#36>", line 1, in <module>
now save the commands and run the program
v=u+a*t
and you will get result as
TypeError: can't multiply sequence by non-int o
initial speed = 5.0
u=float(u);a=float(a);t=float(t)
enter the time 0.5
v=u+a*t; h=u*t+0.5*a*t**2
height at time 0.50 s is 1.27 m
print ("Speed at %2.1f s is %3.2g m/s and hight
name = input("enter your name ") %(t,v,h))
enter your name Subhayan output
last= input ("enter your last name ") initial speed in m/s 5.0
enter your last name Biswas acceleration in m/s^2 2.1
print (“I know you\’r Mr. %s %s" time in s 1.25
%(name,last))
Speed at 1.2 s is 7.6 m/s and hight is 7.89 m
I know you’r Mr. Subhayan Biswas
, Compound statements in Python:
In general, Python code is a sequence of statements. A simple statement is a single l
doesn't end in a colon.
A compound statement is so called because it is composed of other statements (simple
compound).
Compound statements typically span multiple lines and start with a one-line header en
colon, which identifies the type of statement.
Together, a header and an indented suite of statements is called a clause. A compound
consists of one or more clauses:
Exercise: Type a number and check it is even or
enter your number
it is odd
operator Meaning
enter your number
== Is equal to
it is even
!= Not equal to
< Less than
> Greater than
<= Less than or equals to
>= greater than or equals to
and Both are true
or One or the other is true
not Is not true
It is the most important feature for every software language where a user can input s
and the software or function return a value.
For example we have calculated height of an object at time 0.2s with initial velocity
m/s and g = 9.81 m/s2. But I have an wish to find out the height at any time I want.
should I do?
If the process of changing value of the time and write the whole program again and ag
better to quit the use of python and seek for other language.
No, I don’t give this opportunity to you.
There is a command ‘input()’ which serve the purpose.
But we have to follow the steps.
i) Goto start menu and find IDLE Shell 3.9.7 for Python 3.9.7 version and run the programme.
ii) Go to file and select new file and save it with a name.
iii) Right click on the file and select edit with IDEL
iv) Delete all the written words and start freshly your program.
,Exercise- Find out height of an object at a given time and initial speed.
# user input for morethan one variable
Ans.
u= input('initial speed in m/s ')
u=float(input('initial speed = ')) g=9.81
a = input ('acceleration in m/s^2 ')
t=float(input('enter the time ')) h=u*t -
0.5*g*t*t # type conversion is necessary t= input ('time in s ')
for run the program. v=u+a*t
print('height at time %1.2f s is %2.2f Traceback (most recent call last):
m'%(t,h))
File "<pyshell#36>", line 1, in <module>
now save the commands and run the program
v=u+a*t
and you will get result as
TypeError: can't multiply sequence by non-int o
initial speed = 5.0
u=float(u);a=float(a);t=float(t)
enter the time 0.5
v=u+a*t; h=u*t+0.5*a*t**2
height at time 0.50 s is 1.27 m
print ("Speed at %2.1f s is %3.2g m/s and hight
name = input("enter your name ") %(t,v,h))
enter your name Subhayan output
last= input ("enter your last name ") initial speed in m/s 5.0
enter your last name Biswas acceleration in m/s^2 2.1
print (“I know you\’r Mr. %s %s" time in s 1.25
%(name,last))
Speed at 1.2 s is 7.6 m/s and hight is 7.89 m
I know you’r Mr. Subhayan Biswas
, Compound statements in Python:
In general, Python code is a sequence of statements. A simple statement is a single l
doesn't end in a colon.
A compound statement is so called because it is composed of other statements (simple
compound).
Compound statements typically span multiple lines and start with a one-line header en
colon, which identifies the type of statement.
Together, a header and an indented suite of statements is called a clause. A compound
consists of one or more clauses:
Exercise: Type a number and check it is even or
enter your number
it is odd
operator Meaning
enter your number
== Is equal to
it is even
!= Not equal to
< Less than
> Greater than
<= Less than or equals to
>= greater than or equals to
and Both are true
or One or the other is true
not Is not true