Page 37 - 2501_KVS_C-7
P. 37
This is not possible without conversion of string into integer/float.
How to do conversion of inputted values?
Change the 1st line of code in program 3 with the following line and execute your program.
age=int(input("Enter your age"))
It will execute successfully and give you an increased value of age by 2.
To do conversion into integer and float values, int() and float() functions will be used,
respectively.
Program 3: Write a program to calculate the average of 3 inputted numbers.
Code:
A=int(input("Enter value of A"))
B= int(input("Enter value of B"))
C= int(input("Enter value of C"))
S=A+B+C
Avg=S/3
print("Average of Numbers is ",Avg)
Program 4: Write a program to calculate xⁿ, where x is base and n is exponent.
Code:
x= int(input("Enter base value"))
n=int(input("Enter exponent"))
pow=x**n
print(pow)
Program 5: Write a program to calculate Body Mass Index of a person.
[BMI=m/h where m is mass in kg and h is height in meters]
2
Code:
m=int(input("Enter body weight in kilogram"))
h= int(input("Enter height in meter"))
BMI=m/(h**2)
print("Your BMI is ", BMI)
3.2.2 Decision Structure
Decision structure in programming allows you to execute statements based on a given
condition. If the condition evaluates to True, one set of statements is executed.
Otherwise, if the condition evaluates to False, another set of statements is executed.
In Python, decision structure is implemented through if…else statement. The if…else
statement evaluates a test expression and will execute the body of if block only when
the test condition is True. If the condition is False, the body of else block is executed.
Statements that are written at the same indent form a block.
Python Programming 35

