0% found this document useful (0 votes)
1 views3 pages

Python Chapter (2)Variable

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views3 pages

Python Chapter (2)Variable

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Variables

Variables are containers for storing data values.

Creating Variables

Python has no command for declaring a variable.


A variable is created the moment you first assign a value to it.

Declare & Assign

variableName=value

Eg. a=1000.00 ,a=”pikachu” // = assignment operator(right to left assign)

a=100 , a=”Hello”

Python has several built-in data types.

int (integer)
float (floating-point number)
str(string)
bool (Boolean) …. Etc.

Example (1)

name="Mg Mg"
age=15
weight=100
height=5.8
marriage=False
print(name,"\t",type(name))
print(age,"\t",type(age))
print(weight,"\t",type(weight))
print(height,"\t",type(height))
print(marriage,"\t",type(marriage))

Example (2)

name=input("Enter your name:")


age=input("Enter your age:")
print ("Student Name=",name)
print ("Name Data Type=",type(name))
print ("Age="+str(age),"\nAge Data Type=",type(age))
Arithmetic Operator

Eg. 1+2*3=7

Eg. (1+2)*3=9

Operator Precedence

Bracket, Of, Division, Multiplication, Addition, Subtraction // () of / * + -

Example (3)

num1=int(input("Enter First Number:"))


num2=int(input("Enter Second Number:"))
print ("Sum=",num1+num2)

Example (4)

name= input("Enter Employee Name:")


salary = input("Enter salary:")
company = input ("Enter Company name:")
print("Printing Employee Details")
print ("Name", "Salary", "Company")
print (name, salary, company)

Example (5)

myan=int(input("Enter Myanamr Mark:"))


eng=int(input("Enter English Mark:"))
math=int(input("Enter Mathematics Mark:"))
sum=myan+eng+math
avg=sum/3
print("Total Mark=",sum)
print("Avg Mark"+str(avg))

The Python math module is a built-in library that provides access to mathematical functions. It includes
functions for basic operations like addition, subtraction, multiplication, division, and exponentiation. The math
module can help with tasks like calculating the area of a circle, calculating the sine of an angle, or finding the
square root of a number. It also provides constants such as pi, etc.

To use the math module, you need to import it using the "import" keyword.

Exercise (1)
Exercise (2)

Write a Python program that accepts the user's first and last name and prints them in reverse order with a
space between them.

Exercise (3)

Write a Python program that will accept the base and height of a triangle and compute its area.
Formula (b*h/2)

You might also like