ASSIGNMENT NO 1
COMPUTER PROGRAMMING
NAME: MODOOD FAROOQ
ROLL NO:4-15/2024/011
DEPART: BS ELECTRICAL
9/17/2025 ENGINEERIING TECHNOLOGY
TEACHER: SIR MUDASSIR
1. Describe the importance of Python as a programming language for beginners.
2. Discuss the difference between a compiler and an interpreter with respect to Python.
3. Apply arithmetic operators in a program that takes two numbers as input and prints their sum,
difference, product, and quotient.
4. Carry out a program that checks whether a given number is even or odd.
5. Demonstrate the use of conditional statements by creating a program that accepts marks of three
subjects, calculates the average, and prints the grade (A, B, C, or Fail).
6. Illustrate the use of decision-making by writing a program to check whether a year is a leap year.
7. Prepare a program that takes three numbers and prints the largest one using nested ifelse.
8. Use conditional logic in a program that takes a person’s age as input and classifies them as Child,
Teenager, Adult, or Senior Citizen.
9. Demonstrate a calculator program that accepts two numbers and an operator (+, -, *, /) and
computes the result.
10. Solve an electricity billing problem with the following conditions:
10. Solve an electricity billing problem with the following conditions: • Units ≤ 100 → rate = 5 per unit •
Units 101–200 → rate = 7 per unit • Units > 200 → rate = 10 per unit Program should display the total
bill.
1. Importance of Python for Beginners
Python is a good programming language for beginners because it is easy to read and write. Its
syntax is simple and looks like normal English, which helps beginners learn programming
concepts without confusion. Python is also very popular and can be used in many fields like web
development, data analysis, and artificial intelligence. There are many resources and libraries
available that make it easier to learn and create programs.
2. Difference Between Compiler and Interpreter with Respect to Python
A compiler translates the whole program into machine code before it runs, making the program
fast but requiring compilation first. An interpreter reads and executes the code line by line.
Python uses an interpreter, which means it runs code step by step. This is helpful for beginners
because they can test and find errors quickly while coding.
3. Program Using Arithmetic Operators
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
print("Sum:", num1 + num2)
print("Difference:", num1 - num2)
print("Product:", num1 * num2)
if num2 != 0:
print("Quotient:", num1 / num2)
else:
print("Quotient: Cannot divide by zero")
4. Program to Check Even or Odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")
5. Program to Calculate Average and Grade
mark1 = float(input("Enter marks for subject 1: "))
mark2 = float(input("Enter marks for subject 2: "))
mark3 = float(input("Enter marks for subject 3: "))
average = (mark1 + mark2 + mark3) / 3
if average >= 80:
grade = "A"
elif average >= 60:
grade = "B"
elif average >= 40:
grade = "C"
else:
grade = "Fail"
print("Average Marks:", average)
print("Grade:", grade)
6. Program to Check Leap Year
year = int(input("Enter a year: "))
if (year % 4 == 0) and (year % 100 != 0 or year % 400 == 0):
print(year, "is a leap year.")
else:
print(year, "is not a leap year.")
7. Program to Find Largest Number Using Nested If-Else
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if num1 > num2:
if num1 > num3:
largest = num1
else:
largest = num3
else:
if num2 > num3:
largest = num2
else:
largest = num3
print("The largest number is:", largest)
8. Program to Classify Age
age = int(input("Enter your age: "))
if age < 13:
print("You are a Child.")
elif age < 20:
print("You are a Teenager.")
elif age < 60:
print("You are an Adult.")
else:
print("You are a Senior Citizen.")
9. Calculator Program
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
operator = input("Enter an operator (+, -, *, /): ")
if operator == "+":
result = num1 + num2
elif operator == "-":
result = num1 - num2
elif operator == "*":
result = num1 * num2
elif operator == "/":
if num2 != 0:
result = num1 / num2
else:
result = "Error! Division by zero."
else:
result = "Invalid operator."
print("Result:", result)
10. Electricity Billing Program
units = float(input("Enter the number of units consumed: "))
if units <= 100:
bill = units * 5
elif units <= 200:
bill = units * 7
else:
bill = units * 10
print("Total electricity bill: Rs.", bill)