Application of ICT ASSIGNMENT 2
Application of ICT ASSIGNMENT 2
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
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
TASK NO 5
CODE :-
length = 12.5
width = 10.75
price_per_sqm = 500
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): "))
OUTPUT :-
TASK 12 :-
CODE :-
OUTPUT :-
TASK 13 :-
Code :-
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)
if substring_to_check in user_string:
substring_exists = True
else:
substring_exists = False
OUTPUT:-
TASK 15 :-
CODE :-
people = []
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}")
OUTPUT :-
TASK 16 :-
CODE :
people = [
("NOSHAIRWAN", 30),
("ALI", 25),
("SUMEAIR", 35),
("HUUDIA", 28),
("KHIZER ", 22)
]
TASK 17 :-
CODE :-
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
OUTPUT :-
TASK 18 :-
CODE :-
def calculate_simple_interest(principal, rate, time):
return (principal * rate * time) / 100
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(':')
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
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)