Lab 2 Manual - Programming For Business Lab
Lab 2 Manual - Programming For Business Lab
Before you start this lab, you must have an environment set up on your computer to run a
python code. Run the following simple code which displays a message “Hello World!”
print("Hello World")
Understanding Variables:
Imagine you have a problem to solve that requires certain data, like keeping track of numbers.
Instead of writing the numbers down, in programming, you store them in variables—labeled
containers that hold the data you need to work with.
x = 10
Variables can have any name you choose, and they hold values that can be changed as
needed. Their name is what you use to access and work with the stored data.
You can apply operations on the variables and store result in a new variable
x = 10
y = 5
ans = x + y
You can store the following types of data based on your need
● Integer values (for example 5,10,100 etc)
● Decimal Values - also called float values (for example 1.2, 12.1 100.2 etc)
● Boolean Values (with value either being true or false)
● Character Value (for example ‘a’, ‘b’, ‘z’ etc)
● String Value (for example “abc”, “my name” etc)
Understanding Input/Output:
In the Python code above, the values of x and y are directly written into the code by the
developer (the person who writes the code). These are known as hardcoded values. Unlike
developers, end users interact with the finished software. If you want to receive input from end
users and display output back to them, you'll use the input and print functions in Python. Try
executing the following python code
x = int(input("Enter the first number: "))
y = int(input("Enter the second number: "))
ans = x + y
print("The sum is:", ans)
# String input
name = input("Enter your name: ")
print("Your name is:", name)
# Integer input
age = int(input("Enter your age: "))
print("Your age is:", age)
# Float input
height = float(input("Enter your height in meters: "))
print("Your height is:", height)
In Python, you can perform basic arithmetic operations using the following symbols:
x = 10
y = 3
print("Addition:", x + y) # Output: 13
print("Subtraction:", x - y) # Output: 7
print("Multiplication:", x * y) # Output: 30
print("Modulus:", x % y) # Output: 1
Understanding Comments:
In Python, comments are used to explain the code and make it more readable. They are
especially useful for describing what specific parts of your code do, which can be helpful for
both you and others who may read your code later.
Lab Questions:
● Write a Python program that takes the obtained marks and total marks as input and
displays the percentage as output.
● Write a Python program that takes the principal amount, rate of interest, and time (in
years) as input, and calculates and displays the simple interest.
Formula: Simple Interest = (Principal * Rate * Time) / 100
● Write a Python program that takes the temperature in Celsius as input and converts it to
Fahrenheit.
● Write a Python program that takes the length and width of a rectangle as input and
calculates and displays its area.
● Imagine you have an infinite number of tables, each with a seating capacity of x people.
You have a total of n people to seat. The tables must be completely filled before starting
to fill another table. Write a Python program that takes the seating capacity x and the
total number of people n as input, and calculates how many people will be left without a
table after all the tables that can be completely filled are full.