0% found this document useful (0 votes)
28 views20 pages

Application of ICT ASSIGNMENT 2

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)
28 views20 pages

Application of ICT ASSIGNMENT 2

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/ 20

.

Application Of ICT
ASSIGNMENT NO 2
NAME : Noshairwan haider
CLASS: EE-16-A
CMS ID : 507575

TASK NO 1
1)RESULT :- “-30”
2)RESULT :- “ 48.6 “
3)RESULT :- “ 151.4 ”
4)RESULT :- “ 4.19999 ”
5)RESULT:- “ -48 ”
6)RESULT:- “ 106.5 ”
7)RESULT:- “ 41 ”
8)RESULT:- “ 6.8 ”
9)RESULT:- “ 15.569323441926606 ”
10) RESULT :- “ 2.95”
11) RESULT :- “ 11.4 ”
12) RESULT :-“ 48 ”
13) RESULT :- “ 15 ”
14) RESULT :- “ 148 ”
15)RESULT :- “ 49.5 ”
16)RESULT :- “ -13 ”
17)RESULT :- “ 9 ”
18)RESULT :- “ 49 ”
19)RESULT :- “ 17 ”
20)RESULT : “ 53.0 ”

TASK NO 2
CORRECTED CODE ARE AS FOLLOWING
1) total = int("10") + 20 / 2
2) my_tuple = (1, 2, 3)
3) if 5 > 10:
print("Invalid")
4) my_dict = {"name": "Alice", "age": 25}
age = my_dict["age"]

5) import math
result = math.sqrt(16) + 2 * 3 ** 2
6) print("Hello World")
7) file = open("data.txt", "r")

TASK NO 3
CODE:-
principal = 1000
rate = 5
time = 3

simple_interest = (principal * rate * time) / 100

print("The Simple Interest is: " + str(simple_interest))


OUTPUT :-

TASK NO 4

Code :-

principal = 1000
rate = 5
time = 3
rate_per_year = rate / 100

one_plus_rate = 1 + rate_per_year
compound_factor = one_plus_rate ** time

final_amount = principal * compound_factor

print("The Final Amount after applying compound interest is: $" +


str(final_amount))
OUTPUT:-

TASK NO 5

CODE :-

length = 12.5
width = 10.75

price_per_sqm = 500

area = length * width

total_cost = area * price_per_sqm


rounded_total_cost = round(total_cost)
print("The total cost to carpet the room is: $", rounded_total_cost)

OUTPUT :-

TASK NO 6 :-

CODE :-

temp = -17.5
absolute_temp = abs(temp)
kelvin = temp + 273.15
fahrenheit = (temp * 9 / 5) + 32
print("Absolute Temperature :", absolute_temp)
print("Temperature in Kelvin :", kelvin)
print("Temperature in Fahrenheit :", fahrenheit)

OUTPUT :-
TASK NO 7 :-
CODE :-

import math
radius = 7.5
volume = (4/3) * math.pi * (radius ** 3)
rounded_volume = round(volume, 2)
print("The volume of the sphere is:", rounded_volume)

OUTPUT:-

TASK 8 :-
CODE :-

positive_integer = None
while True:
user_input = input("Please enter a positive integer: ")
try:
positive_integer = int(user_input)
if positive_integer > 0:
print("Thank you! You entered:", positive_integer)
break
else:
print("Error: The number must be positive. Try again.")
except ValueError:
print("Error: That's not a valid number. Please enter a positive integer.")

OUTPUT :-

TASK 9 :-
CODE:-

positive_integer= 6
factorial = 1
for i in range(1, positive_integer + 1):
factorial *= i
print("The factorial of", positive_integer, "is:", factorial)

OUTPUT :-

TASK 10 :-
CODE :-
TASK 11 :-

CODE :-

grades = []

def get_grade(mark):
if mark >= 90 and mark <= 100:
return 'A'
elif mark >= 80 and mark < 90:
return 'B'
elif mark >= 70 and mark < 80:
return 'C'
elif mark >= 60 and mark < 70:
return 'D'
else:
return 'F'

for i in range(10):
while True:
try:
mark = int(input("Please enter the marks for student " + str(i + 1) + "
(between 0 and 100): "))

if mark >= 0 and mark <= 100:


grade = get_grade(mark)
grades.append(grade)
print("Student " + str(i + 1) + " got a grade of: " + grade)
break
else:
print("Oops! Please enter a number between 0 and 100.")
except ValueError:
print("That doesn't seem to be a valid number. Try again.")
print("\nSummary of Grades:")
print("Number of A's: " + str(grades.count('A')))
print("Number of B's: " + str(grades.count('B')))
print("Number of C's: " + str(grades.count('C')))
print("Number of D's: " + str(grades.count('D')))
print("Number of F's: " + str(grades.count('F')))

OUTPUT :-

TASK 12 :-
CODE :-

for i in range(1, 11):


for num in range(i, (i * 20) + 1, i):
print(num, end=" ")
print()

OUTPUT :-

TASK 13 :-
Code :-

name_list = list("Noshairwan haider ")


print("List:", name_list)
name_tuple = tuple("Noshairwan haider ")
print("Tuple:", name_tuple)
name_set = set("Noshairwan haider ")
print("Set:", name_set)

OUTPUT:-

TASK 14 :-
print("Enter a string:")
user_string = input()

if len(user_string) >= 3:
first_three = user_string[0:3]
else:
first_three = user_string

if len(user_string) >= 3:
last_three = user_string[-3:]
else:
last_three = user_string

length_of_string = len(user_string)

print("Enter a substring to check if it exists in the string:")


substring_to_check = input()

if substring_to_check in user_string:
substring_exists = True
else:
substring_exists = False

print("First three characters:", first_three)


print("Last three characters:", last_three)
print("Length of the string:", length_of_string)
print("Does the substring exist?", substring_exists)

OUTPUT:-

TASK 15 :-

CODE :-
people = []

def add_person(name, age, hobbies):


person = {
'name': name,
'age': age,
'hobbies': hobbies
}
people.append(person)
print(f"Added {name} to the list.")

def find_people_by_hobby(hobby):
found_people = [person for person in people if hobby in person['hobbies']]
if found_people:
print(f"People who share the hobby '{hobby}':")
for person in found_people:
print(f"- {person['name']} (Age: {person['age']})")
else:
print(f"No one found with the hobby '{hobby}'.")

def count_people_older_than(age_limit):
count = sum(1 for person in people if person['age'] > age_limit)
print(f"Number of people older than {age_limit}: {count}")

add_person("Alice", 30, ["reading", "hiking"])


add_person("Bob", 25, ["hiking", "cooking"])
add_person("Charlie", 35, ["reading", "gaming"])
find_people_by_hobby("reading")
count_people_older_than(28)

OUTPUT :-
TASK 16 :-
CODE :

people = [
("NOSHAIRWAN", 30),
("ALI", 25),
("SUMEAIR", 35),
("HUUDIA", 28),
("KHIZER ", 22)
]

sorted_people = sorted(people, key=lambda person: person[1])

print("Sorted list by age:")


for name, age in sorted_people:
print(f"{name}: {age}")
OUTPUT :-

TASK 17 :-

CODE :-
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

even_numbers = list(filter(lambda x: x % 2 == 0, numbers))

print("Even numbers:", even_numbers)

OUTPUT :-

TASK 18 :-
CODE :-
def calculate_simple_interest(principal, rate, time):
return (principal * rate * time) / 100

def calculate_compound_interest(principal, rate, time):


return principal * (1 + (rate / 100)) ** time

def calculate_area_cost(length, width, price_per_sqm):


area = length * width
return round(area * price_per_sqm)

def volume_of_sphere(radius):
import math
volume = (4 / 3) * math.pi * (radius ** 3)
return round(volume, 2)

def temperature_conversion(temp_celsius):
temp_fahrenheit = (temp_celsius * 9/5) + 32
temp_kelvin = temp_celsius + 273.15
return temp_fahrenheit, temp_kelvin

print(calculate_simple_interest(1000, 5, 3))
print(calculate_compound_interest(1000, 5, 3))
print(calculate_area_cost(12.5, 10.75, 500))
print(volume_of_sphere(7.5))
print(temperature_conversion(-17.5))

output :-
TASK 19 :-

CODE :-
def read_grades(file_path):
students = []
with open(file_path, 'r') as file:
for line in file:
name, scores = line.split(':')

scores = list(map(int, scores.split(',')))


students.append({'name': name, 'scores': scores})
return students

def calculate_average(students):
for student in students:
student['average'] = sum(student['scores']) / len(student['scores'])

def pass_fail(students):
for student in students:
if student['average'] >= 50:
print(f"{student['name']} has passed with an average of
{student['average']}")
else:
print(f"{student['name']} has failed with an average of
{student['average']}")

def above_90(students):
top_students = [student['name'] for student in students if
student['average'] > 90]
print("Students scoring above 90:", top_students)

students = read_grades('grades.txt')
calculate_average(students)
pass_fail(students)
above_90(students)

TASK 20 :-
CODE :-
import string

def count_alphabets(file_path):
counters = [0] * 26 # List to store count of each alphabet
with open(file_path, 'r') as file:
text = file.read().lower() # Convert content to lowercase

for char in text:


if 'a' <= char <= 'z':
counters[ord(char) - ord('a')] += 1

return counters
def display_histogram(counters):
for i, count in enumerate(counters):
print(f"{chr(i + ord('a'))}: {'#' * count}")

alphabet_count = count_alphabets('textfile.txt')
display_histogram(alphabet_count)

You might also like