0% found this document useful (0 votes)
15 views

AI Lab 1

This document contains a Python assignment submitted by Muhammad Umar Nawaz Janjua to his instructor Engr. Waleed. The assignment includes 3 tasks - writing programs to 1) calculate the number of days between two dates, 2) convert pressure units, and 3) evaluate a grade based on marks. For each task, the student provides the required code and sample output. In conclusion, the student states that he learned the basic usage, syntax, and tasks of Python through this lab.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

AI Lab 1

This document contains a Python assignment submitted by Muhammad Umar Nawaz Janjua to his instructor Engr. Waleed. The assignment includes 3 tasks - writing programs to 1) calculate the number of days between two dates, 2) convert pressure units, and 3) evaluate a grade based on marks. For each task, the student provides the required code and sample output. In conclusion, the student states that he learned the basic usage, syntax, and tasks of Python through this lab.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

AI Lab 1

BSE 6A
Fall 2023
Submitted by: Muhammad Umar Nawaz Janjua.
Enrolment number: 01-131202-039.
Submitted to: Engr. Waleed.

Department of Software Engineering


Bahria University Islamabad Campus
Objectives
• Introduction to Python.
Tools Used
• Visual Studio Code
• Snipping tool

Tasks
1: Write a Python program to calculate number of days between two dates.
Sample dates: (2014, 7, 2), (2014, 7, 11)
Expected output: 9 days
Code:
def myDateTime(date1, date2):
year1, month1, day1 = date1
year2, month2, day2 = date2

date1Seconds = year1 * 86400 * 365 + month1 * 86400 * 30 + day1 * 86400


date2Seconds = year2 * 86400 * 365 + month2 * 86400 * 30 + day2 * 86400

dif = abs(date1Seconds - date2Seconds)

return dif // 86400

year1 = int(input("Enter 1st year: "))


mon1 = int(input("Enter 1st month: "))
day1 = int(input("Enter 1st day: "))

year2 = int(input("Enter 2nd year: "))


mon2 = int(input("Enter 2nd month: "))
day2 = int(input("Enter 2nd day: "))

date1 = (year1, mon1, day1)


date2 = (year2, mon2, day2)
result = myDateTime(date2, date1)

print(result)

Output:

2: Write a Python program to convert pressure in kilopascals to pounds per


square inch, a millimeter of mercury (mmHg) and atmosphere pressure.
kpa = float(input("Enter pressure in kilopascals: "))

psi = kpa / 6.894757293168361


print("Pressure in pounds per square inch (psi): ", round(psi, 2))

mmhg = kpa * 7.50062


print("Pressure in millimeters of mercury (mmHg): ", round(mmhg, 2))

atm = kpa / 101.325


print("Pressure in atmospheres (atm): ", round(atm, 2))

Output:
3. Write a program in python to evaluate grade according to marks.
Code:
def calGrade(marks):
if marks > 85 and marks <= 100:
print("Grade: A")
elif marks >= 80 and marks <= 85:
print("Grade: A-")
elif marks >= 75 and marks <= 79:
print("Grade: B+")
elif marks >= 71 and marks <= 74:
print("Grade: B")
elif marks >= 68 and marks <= 70:
print("Grade: B-")
elif marks >= 64 and marks <= 67:
print("Grade: C+")
elif marks >= 60 and marks <= 63:
print("Grade: C")
elif marks >= 57 and marks <= 59:
print("Grade: C-")
elif marks > 53 and marks <= 56:
print("Grade: D+")
elif marks > 50 and marks <= 52:
print("Grade: D")
elif marks > 0 and marks <= 49:
print("Grade: F")
else:
print("Grade: invalid Input please enter between (0-100")

marks = int(input("Please enter marks: "))


calGrade(marks)

Output:

Conclusion:
By the end of this lab, we learned about the basic usage of python, its syntax and performed all tasks.

You might also like