0% found this document useful (0 votes)
13 views3 pages

Even Number Check and String Functions

String Functions

Uploaded by

jpcapispisan31
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)
13 views3 pages

Even Number Check and String Functions

String Functions

Uploaded by

jpcapispisan31
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

# Given. The remainder when n is divided by 2 is equal to 0.

# Step 1: Identify the variables (objects) and the constants (numbers)


# n, 2, 0

# Step 2: Identify operator keywords


# remainder - % (modulus operator)
# is equal to - ==

# Step 3 and 4: Combine and use parenthesis while following:


# Order of Precedence (PEMDAS)
# Parenthesis
# Exponentation
# Multiplication, Division, Floor Division, Modulus
# Addition, Subtraction
# Comparison (==, !=, >, <, >=, <=)
# Logical (and, or, not)

# (n % 2) == 0

# Step 5 and 6: Check and Test


# n = 24
# # form = (n % 2) == 0
# # print(form)

# if (n % 2) == 0:
# print(str(n) + " is an even number, meaning, the remainder is " + str(n % 2) + ".")
# else:
# print(str(n) + " is an odd number, the remainder was " + str(n % 2) + ".")

# NESTED IF-ELIF-ELSE STATEMENT


# - an if-elif-else statement inside another if-elif-else statement.

# OUTER CONDITION. Given. The remainder when n is divided by 2 is equal to 0.


# NESTED IF-ELSE: n is 20 and below.
# n = 24

# if (n % 2) == 0:
# print(str(n) + " is an even number, meaning, the remainder is " + str(n % 2) + ".")
# # NESTED IF-ELSE STATEMENT
# if n <= 20:
# print(str(n) + " is 20 and below.")
# else:
# print(str(n) + " is not 20 and below.")
# else:
# print(str(n) + " is an odd number, the remainder was " + str(n % 2) + ".")

# BUILT-IN String Functions:


# 1. len() - counts the number of characters in a string including spaces.
# school = "FCPC"
# length = len(school)
# print(length) # 4 characters

# section = "BSIT 1B"


# length_section = len(section)
# print(length_section) # 7 characters (including whitespaces)

# name = "Ramon Joseph Verdon"


# print(len(name)) # 19 characters (including whitespaces)

# Upper() - converts all characters to uppercase.


# school = "first city providential college"
# upper_school = [Link]()
# print(upper_school) # FIRST CITY PROVIDENTIAL COLLEGE

# Lower() - converts all characters to lowercase.


# email = "MYEMAIL123@[Link]".lower()
# # clean_email = [Link]()
# # print(clean_email)
# print(email) # myemail123@[Link]

# email = input("Enter email: ").lower()


# print("Your clean email is " + email) # myemail123@[Link]

# Title() - converts all characters to titlecase.


# Title case is when every first letter of a word is uppercase and the rest are lowercase.
# e.g. Juan Dela Cruz & Information Technology
# school = "first CITY pROVIDENTIAL COLLege"
# title_school = [Link]()
# print(title_school) # First City Providential College

# strip() - removes starting and ending whitespaces.


# username = " admin123 ".strip()
# correct_username = "admin123"
# print(username == correct_username) # True

# username = " admin123 "


# clean_username = [Link]()
# print(username)
# print(clean_username) # True

# Replace() - replaces all occurrences in a string.


# NOTE: replace() is case-sensitive.
# sample = "This is a test string. We are doing test here."
# sample_replaced = [Link]("test", "SAMPLE")
# sample_replaced = [Link](" ", "") # remove all whitespaces.
# print(sample_replaced) # This is a SAMPLE string. We are doing SAMPLE here.

# name = "Ramon Joseph Verdon".replace("D", "si") # D cant be found in lowercase.


# print(name) # Ramon Joseph Verdon

# # count() - counts the number of occurrences in a string.


# sample = "This is a test string. We are doing test here." # 1 occurrence of "te st", 2
occurrences of "test"
# # count_sample = [Link]("test")
# count_sample = [Link]("is") # 2 occurrences of "is ", 1 occurence of " is", 2
occurrences of "is"
# print(count_sample) # 2 occurrences of "test"

# # ADDITIONAL
# email = 'ramon joseph verdon @ [Link]'
# clean = [Link](" ", "").lower()
# print(clean) # ramonjosephverdon@[Link]

You might also like