0% found this document useful (0 votes)
16 views2 pages

Assignment 43

The document provides examples of data types in Python, including integers, floats, strings, lists, and dictionaries. It also demonstrates operations such as calculating averages, manipulating lists, and character encoding. Additionally, it showcases how to print and access elements from lists and tuples.

Uploaded by

Jr
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)
16 views2 pages

Assignment 43

The document provides examples of data types in Python, including integers, floats, strings, lists, and dictionaries. It also demonstrates operations such as calculating averages, manipulating lists, and character encoding. Additionally, it showcases how to print and access elements from lists and tuples.

Uploaded by

Jr
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

Python 3

1. x = 123
y = -45e7
z = 45.j
a = 'Maria'
b = ('abcd', 786, 2.23, 'john', 70.2)
c = '$'

print("Data type of x:", type(x))


print("Data type of y:", type(y))
print("Data type of z:", type(z))
print("Data type of a:", type(a))
print("Data type of b:", type(b))
print("Data type of c:", type(c))

2. a) Average of four grades → float


b) Number of months in a year → int
c) Perimeter of URS Morong Campus → float
d) Numbers in a lottery → list / set of int
e) Distance from Morong to Quezon City → float
f) Single-character prefix of class sections → str (single char)
g) Grade roster → list of int / float
h) Names of URS Campuses → list of str
i) Indexed information about CoEng class list → dictionary (dict)
j) The days in a week → list / tuple of str

3. grades = [85, 90, 88, 92]


average = sum(grades) / len(grades)
print("Average of grades:", average, type(average))

months = 12
print("Months in a year:", months, type(months))

perimeter = 1234.56
print("Perimeter:", perimeter, type(perimeter))

lottery_numbers = {5, 12, 19, 33, 45}


print("Lottery numbers:", lottery_numbers, type(lottery_numbers))

distance = 67.8
print("Distance:", distance, type(distance))

prefix = 'A'
print("Section prefix:", prefix, type(prefix))

roster = [90, 85, 88, 75]


print("Roster:", roster, type(roster))
campuses = ["Morong", "Tanay", "Antipolo"]
print("Campuses:", campuses, type(campuses))

coeng_class = {"ECE1": "Frince", "ECE2": "Juan"}


print("CoEng class list:", coeng_class, type(coeng_class))

days = ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")


print("Days in a week:", days, type(days))

4. print("'C' - 1:", chr(ord('C') - 1))


print("'o' + 8:", chr(ord('o') + 8))
print("'l' - 2:", chr(ord('l') - 2))
print("'i' + 3:", chr(ord('i') + 3))
print("'n' - 4:", chr(ord('n') - 4))

5. list1 = ['xyz', 7.86, 223, 'Juan', 70.2]


list2 = [1, 23, 'jj']

# 1) Print the two lists in a single line


print(list1, list2)

# 2) Print last & third elements


print("list1 last:", list1[-1], " third:", list1[2])
print("list2 last:", list2[-1], " third:", list2[2])

# 3) Elements starting from 2nd till 3rd


print(list1[1:3])

# 4) From 3rd element onwards


print(list1[2:])

# 5) Print list2 two times


print(list2 * 2)

# 6) Concatenated lists
print(list1 + list2)

You might also like