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

Phytoon Example Coding py

The document contains Python code demonstrating various programming concepts including numeric operations, string concatenation and indexing, list operations, dictionary manipulation, type conversion, and multiline strings. Each activity is labeled and includes print statements to display results and types of operations performed. The code serves as a practical exercise for understanding basic data types and structures in Python.

Uploaded by

jacamadenzryzza
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Phytoon Example Coding py

The document contains Python code demonstrating various programming concepts including numeric operations, string concatenation and indexing, list operations, dictionary manipulation, type conversion, and multiline strings. Each activity is labeled and includes print statements to display results and types of operations performed. The code serves as a practical exercise for understanding basic data types and structures in Python.

Uploaded by

jacamadenzryzza
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#Denz Ryzza G.

Jacama
#Activity 1: Exploring Numeric Data Types
print("Act.1")
x = 7
y = 2.2

addition = x + y
subtraction = x - y
multiplication = x * y
division = x / y

print("addition:", x + y, "type:", type(x + y))


print("subtraction:", x - y, "type:", type(x - y))
print("multiplication:", x * y, "type:", type(x * y))
print("division:", x / y, "type:", type(x / y))
print("")

#Activity 2: String Concatenation and Indexing


print("Act.2")
str1 = "eat"
str2 = "log"

'Concatenated_str' == str1 + str2


first_str1 = str1[0]
middle_str1 = str1[1]
last_str1 = str1[2]
substring_str1 = str1[:3]
substring_str2 = str2[:3]

print("Concatenated String:", str1 + str2 )


print("first character of str1:",first_str1)
print("middle character of str1:",middle_str1)
print("last character of str1:", last_str1)
print("First 3 characters of str1:", substring_str1)
print("First 3 characters of str2:", substring_str2)
print("")

#Activity 3: Lists and Their Operations


print("Act.3")

Family = ["ate", "kuya" , "mama", "papa"]


second_element = Family [1]
last_element = Family [3]
Family .append("bunso")
Family.remove("ate")
kuya_count = Family.count("kuya")
print("Original list:", Family)
print("Second element:",second_element )
print("Last element:",last_element )
print("List after appending 'bunso':", Family)
print("List after removing 'ate':", Family)
print("Count of 'kuya' in the list:",kuya_count)
print("")

#Activity 4: Dictionaries - Storing and Accessing Data


print("Act.4")
person = {"name": "denz", "Age ": 20, "city": "Dipolog"}
person["age"] = 20
person["job"] = "Engineer"
del person["city"]

print("Original dictionary :", person)


print("Updated dictionary:", person)
print("Dictionary after adding job:", person)
print("Dictionary after removing city:", person)
print("")

#Activity 5: Type Conversion


print("Act.5")
a = "777"
b = 2.2
c = 3

a_to_int = int(a)
b_to_int = int(b)
c_to_str = str(c)
a_to_float = float(a)

print("String '777' to int:", a_to_int)


print("Float 2.2 to int:",b_to_int)
print("Integer ;3 to string:", c_to_str)
print("String '777' to float:",a_to_float)
print("")

#Activity 6: Multiline String


print("Act.6")
lyrics = """Andres Bonifacio CollegeOur Alma Mater Dear Ever ready, kind and
sincerePledge to serve all far and near Proudly stands in quite and peaceful
grounds.With green fields all aroundGraced with air and healthful sunshineProviding
a setting so divineHail to thee! Fair Alma Mater,Thy beauty inspires us to
care,We're grateful much for all you've done.Preparing us for a better lifeWe're
joyful too and thankful.For those who gave us more lightKnowledge, wisdom,
strength, and confidenceLong Live Andres Bonifacio CollegeHail to thee! Fair Alma
Mater,Thy beauty inspires us to care,We're grateful much for all you've
done.Preparing us for a better lifeWe're joyful too and thankful.For those who gave
us more lightKnowledge, wisdom, strength, and confidenceLong Live Andres Bonifacio
College."""

check_beauty = "beauty" in lyrics


check_long = "long" in lyrics
check_fare = "fare" in lyrics
check_not_beauty = "beauty" not in lyrics
check_not_long = "long" not in lyrics
check_not_fare = "fare" not in lyrics

text_length = len(lyrics)

print("Beauty in lyrics:" ,check_beauty)


print("Long in lyrics:" ,check_long)
print("Fare in lyrics:" ,check_fare)
print("Beauty NOT in lyrics:" ,check_not_beauty)
print("Long NOT in lyrics:" ,check_not_long)
print("Fare NOT in lyrics:" ,check_not_fare)
print("Total length of the text:" ,text_length)
print("")

You might also like