# A palindrome is a word or a phrase that is the same when read both forward and backward. Example are: "bob", "sees" or "never odd or even" (ignoring spaces)
# Write a program whose input is a word or phrase and that outputs whether the input is a plaindrome 

# Ex: If the input is: bob 
# The output is: palindrome: bob 

#Ex: If the input is: bobby 
# The output is not a palindrome: bobby 

#Hint: Start by removing spaces. Then check if the string equals itself in reverse 

text = input()

clean_text = text.replace( " ", "").lower()

if clean_text == clean_text[::-1]:
    print(f"palindrome: {text}")
else: 
    print(f"not a plaindrome: {text}")






#complete the calc_average() function that has an integer list parameter and returns the average value of the elements in the list as a float 
#Ex: if the input list is: 
# 1,2,3,4,5 
#Then the returned average will be: 
# 3.0 

def calc_average(nums): 
    if len(nums) == 0: 
        return 

    return sum(nums) / len(nums)

if __name__ == '__main__': 
    nums = [1,2,3,4,5]
    print(calc_average(nums))



# Create a solution that accepts three integer inputs representing the number of times an employee travels to a job site in a month
# Output the total distance traveled to two decimal places according to the miles each employee commutes to the job site: 

# Employee A: 15.62 miles 
# Employee B: 41.85 miles 
# Employee C: 32.67 miles 

# The solution output should be in the format: 
# Distance total_miles , traveled_miles

# Sample Input/ Output: 

#If the input is: 3, 10 ,5 

# then the expected output is 
#Distance: 628.71 miles 



# Employee distances per trip
A_MILES = 15.62
B_MILES = 41.85
C_MILES = 32.67

# accept three integer inputs
print("Enter the number of days Employee A travels to job:")
employee_a = int(input())

print("Enter the number of days Employee B travels to job:")
employee_b = int(input())

print("Enter the number of days Employee C travels to job:")
employee_c = int(input())

# calculate total distance
def total_distance(a_trips, b_trips, c_trips):
    total = (a_trips * A_MILES) + (b_trips * B_MILES) + (c_trips * C_MILES)
    return total

# call the function
total = total_distance(trip_a, trip_b, trip_c)

# output combined mileage
print(f"Distance: {total:.2f} miles")

# ----------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create a solution that accepts an integer input representing any number of ounces. Output the converted total number of tons, pounds
# and remaining ounces based on the value of the input ounces. There are 16 ounces in a pound, and 2,000 pounds in a ton. 

#The solution output should be in the format: 
# Tons: value1 Pounds: value_2 Ounces: value_3 

#Sample Input/ Output 
# If the input is 32,500

#Then the expected output is Tons: 1 Pounds 31 Ounces: 4 



#there are 16 ounces in a pound and 2000 pounds in a ton
#solution accepts an integer value representing any number of ounces
#solution outputs the converted tons, pounds, and ounces represented by the input value of ounces

print("Enter the number of ounces to convert:")
ounces = int(input())

#convert ounces to pounds and tons
#16 ounces in a pound  

pounds = ounces // 16 

#2000 pounds in one ton 
tons = pounds // 2000 

remaining_ounces = ounces % 16 
remaining_pounds = pounds % 2000
#output number of tons, remaining pounds, and remaining ounces
print(f"Tons:", tons)
print(f"Pounds:", remaining_pounds)
print(f"Ounces:" ,remaining_ounces)

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Create a solution that accepts an integer input representing the index value for any of the seven elements in the following list:
#data_mixture = ["Python is fun", 2024, 5.67, ["apple", "banana", "coconut"], False, None,{"name": "John", "age": 25}]
 
#The solution should perform the following:
#Retrieve the element at the given index.
#Determine its data type using the type() function and its .name attribute.
#Check if the element belongs to one of the following categories:

#if 
#If the element is "iterable" (e.g., list, str, dict), output, "This element is iterable."
#elif
#If the element is numeric (e.g., int, float), output, "This element is numeric."
#else
#For other data types not in these categories, output, "This is a different data type."
#The solution output should be in the format:
print
#Element: [element_value], Type: [data_type], Message: [category_message]
 
#Sample Input and Output:
#If the input is
#Enter index: 3
#then the expected out is
#Element: ['apple', 'banana', 'coconut'], Type: list, Message: This element is iterable.
 
#Alternatively, if the input is
#Enter index: 1
#then the expected output is
#Element: 2024, Type: int, Message: This element is numeric.
 
#Alternatively, if the input is
#Enter index: 4
#then the expected output is
#Element: False, Type: bool, Message: This is a different data type.


# list of mixed data elements
data_mixture = ["Python is fun", 2024, 5.67, ["apple", "banana", "coconut"], None, {"name": "John", "age": 25}]

# input for index
print("Enter index:")
index = int(input())

element = data_mixture[index]
data_type = type(element).__name__

# determine message
if isinstance(element, (list, str, dict)):
    message = "This element is iterable."
elif isinstance(element, (int, float)):
    message = "This element is numeric."
else:
    message = "This is a different data type."

# required output format
print(f"Element: {element}, Type: {data_type}, Message: {message}")

#PRACTICE CODE 
# The Fibonacci sequence begins with 0 and then 1 follows. All subsequent values are the sum of the previous two, ex: 0, 1, 1, 2, 3, 5, 8, 13. Complete the fibonacci() 
#function, which has an index, n (starting at 0), as a parameter and returns the nth value in the sequence. Any negative index values should return -1.

def fibonacci(n):
    if n < 0: 
        return -1

    if n == 0: 
        return 

    if n == 1: 
        return 1 

    previous = 0 
    current = 1 

    for _in range(2, n + 1): 
        next_val = previous + current 
        previous = current 
        current = next_val 
    return current

if __name__ == '__main__': 
    start_num = int(input())
    print(f'fibonacci({start_num}) is {fibonacci(start_num)} ')


--------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Create a solution that accepts any three integer inputs 
#representing the base (b1, b2) and height (h) measurements of a trapezoid in meters. 
#Output the exact area of the trapezoid in square meters as a float value. 
#The exact area of a trapezoid can be calculated by summing the two bases, multiplying the sum by the height, and then dividing by two.
#Trapezoid Area Formula:
#A = ((b1 + b2) * h) / 2
#The solution output should be in the format:
#Trapezoid area: area_value square meters
 
#Sample Input and Output:
#If the input is
#Enter base 1: 3 Enter base 2: 4 Enter height: 5
#then the expected output is
#Trapezoid area: 17.5 square meters

#Alternatively, if the input is
#Enter base 1: 3 Enter base 2: 5 Enter height: 7
#then the expected output is
#Trapezoid area: 28.0 square meters

#PRACTICE CODE 
#solution accepts three integer values representing base and height measurements of a trapezoid
#first and second integers represent base 1 and base 2; third integer represents height 
#solution outputs the trapezoid area in square meters using formula A = ((b1 + b2) * h) / 2)
print("Enter base 1: ")
base_1 = float(input())
print("Enter base 2: ")
base_2 = float(input())
print("Enter height: ")
height = float(input())

#calculate the area of a trapezoid
area = ((base_1 + base_2) * height) / 2

#ouput exact trapezoid area based on input dimensions
print(f"Trapezoid area: {area}", "square meters")
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Create a solution that accepts five integer inputs. 
#Output the sum of the five inputs three times, converting the inputs to the requested data type before finding the sum.
#First output: the sum of the five inputs as an integer value
#Second output: the sum of the five inputs after converting each input to a float value
#Third output: the concatenation of the five inputs after converting each input to a string
#The solution output should be in the format:
#Integer: integer_sum_value Float: float_sum_value String: string_sum_value
 
#Sample Input and Output:
#If the input is
#Enter 1st num: 1 Enter 2nd num: 3 Enter 3rd num: 6 Enter 4th num: 2 Enter 5th num: 7
#then the expected output is
#Integer: 19 Float: 19.0 String: 13627


#PRACTICE CODE 
print("Enter 1st number:")
num_1 = int(input())

print("Enter 2nd number:")
num_2 = int(input())

print("Enter 3rd number:")
num_3 = int(input())

print("Enter 4th number:")
num_4 = int(input())

print("Enter 5th number:")
num_5 = int(input())

# first output: integer sum
integer_value = num_1 + num_2 + num_3 + num_4 + num_5

# second output: float sum
float_value = float(num_1) + float(num_2) + float(num_3) + float(num_4) + float(num_5)

# third output: string concatenation
string_value = str(num_1) + str(num_2) + str(num_3) + str(num_4) + str(num_5)

print(f"Integer: {integer_value}")
print(f"Float: {float_value}")
print(f"String: {string_value}")
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Create a solution that accepts an integer input representing a 9-digit unformatted student identification number. 
#Output the identification number as a string with no spaces.
#The solution output should be in the format:
#111-22-3333
 
#Sample Input and Output:
#If the input is
#Enter Student Identification Number: 154175430
#then the expected output is
#154-17-5430

#Alternatively, if the input is
#Enter Student Identification Number: 1234567890
#then the expected output is
#123-456-7890


#PRACTICE CODE 
#Get student identification number from user 
student_id = int(input("Enter your student identification number: "))

student_id = str(student_id).zfill(9)

#.zfill is a string method in python that pads the left side of a string with zeros until the string is exactly 9 characters long 
format = f" {student_id[:3]} - {student_id[3:5]} - {student_id[5:9]}"

#Output the identification number as string with no spaces 
print(format)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
# TALK ABOUT THIS ONE 
#Create a program that takes an integer input and determines whether it equals one of the values in this predefined list:
#predef_list = [4, -27, 15, 33, -10]

#Define a function named is_in_list() that outputs a Boolean value (True or False) based on the comparison of the input value 
#with the maximum value from predef_list.
#The solution should produce the output in the following format:

#True if the input is in the list, otherwise False.
 
#Is the input present in the list? Boolean_value
 
#Sample Input and Output:
#If the input is
#20
#then the expected output is
#Is the input present in the list? False

#Alternatively, if the input is
#33
#then the expected output is
#Is the input present in the list? True


#PRACTICE CODE 
predef_list = [4, -27, 15, 33, -10]
# Solution accepts an integer input 

#Solution outputs boolean value indicating whether integer input is in predef_list 
#accept integer input 
print("Enter the number to check for in the list:")
user_input = int(input())

#define function to compare input with list values 
def is_in_list(predef_list): 
    if user_input in predef_list: 
        return True 
    else:
        return False 

#output desired statement based on is_in_list() function 
if__name__ == '__main__': 
    result = is_in_list(predef_list)
    print(f"Is the input present in the list? {result}")
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Create a solution that accepts one integer input representing the index value for any of the string elements in the following list:
#frameworks = ["Django", "Flask", "CherryPy", "Bottle", "Web2Py", "TurboGears"]
#Output the string element of the index value entered. 
#Place the solution in a try block and implement an exception of "Error" if an incompatible integer input is provided.
#The solution output should be in the format:
#frameworks_element
 
#Sample Input and Output:
#If the integer input is
#2
#then the expected output is
#CherryPy

#Alternatively, if the integer input is
#7
#then the expected output is
#Error


#PRACTICE CODE 
frameworks = ["Django", "Flask", "CherryPy", "Bottle", "Web2Py", "TurboGears"]

#use try block with exception "Error" when index value is not found in list
#solution accepts an integer input
#solution outputs the corresponding string value for the integer input

#try-block to determine value
try:
  print("Enter the index of the element that you want to extract from the list:")
  index = int(input())

  if 0 <= index < len(frameworks):
      print(frameworks[index])
  else:
      raise IndexError
except:
  print("Error")

  
-------------------------------------------------------------------------------------------------------------------------------------------------------------------

# DOUBLE CHECK THE TASK NOTES ON THIS
Task:
#Create a solution that accepts an integer input representing water temperature in degrees Fahrenheit. 
#Output a description of the water state based on the following scale:
#If the temperature is below 33° F, the water is “Frozen”.
#If the water is between 33° F and 80° F (including 33°), the water is “Cold”.
#If the water is between 80° F and 115° F (including 80°), the water is "Warm".
#If the water is between 115° F and 211° F (including 115°) , the water is “Hot".
#If the water is greater than or equal to 212° F, the water is “Boiling”.
#Additionally, output a safety comment only during the following circumstances:
#If the water is exactly 212° F, the safety comment is, "Caution: Hot!"
#If the water temperature is less than 33° F, the safety comment is, "Watch out for ice!"
#The solution output should be in the format:
#water_state optional_safety_comment
 
#Sample Input and Output:
#If the input is
#Enter the temperature of water: 118
#then the expected output is
#Hot

#Alternatively, if the input is
#Enter the temperature of water: 32
#then the expected output is
#Frozen Watch out for ice!
#open_in_new


#CODE PRACTICE 
#temperature >= 212, water state is "Boiling"
#temperature (115, 211], water state is "Hot"
#temperature [80, 115], water state is "Warm"
#temperature [33, 80), water state is "Cold"
#temperature < 33, water state is "Frozen"
#temperature = 212, safety comment "Caution: Hot!"
#temperature < 33, safety comment "Watch out for ice!"
#solution accepts integer input representing a water temperature
#solution outputs the water state and potential safety comment based on temperature

print("Enter the water temperature:")
temp = int(input())

# safety message
safety = ""

if temp == 212:
    safety = "Caution: Hot!"
elif temp < 33:
    safety = "Watch out for ice!"

# water state
if temp < 33:
    print("Frozen")
elif 33 <= temp < 80:
    print("Cold")
elif 80 <= temp < 115:
    print("Warm")
elif 115 <= temp < 211:
    print("Hot")
else:
    print("Boiling")

if safety:
    print(safety)

--------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Create a solution that accepts an integer input identifying 
#how many different shares of stock are purchased from the Old Town Stock Exchange, 
#followed by an equivalent number of string inputs representing the stock selections. 
#The following dictionary, stock, lists available stock selections as the key and the cost per selection as the value.
#stocks = {'TSLA': 912.86 , 'BBBY': 24.84, 'AAPL': 174.26, 'SOFI': 6.92, 'KIRK': 8.72, 'AURA': 22.12, 'AMZN': 141.28, 'EMBK': 12.29, 'LVLU': 2.33}
#Output the total cost of the purchased shares of stock to two decimal places.
#The solution output should be in the format:
#Total price: $cost_of_stocks
 
#Sample Input and Output:
#If the input is
#Please enter the number of different stocks that you want to purchase: 3 SOFI AMZN LVLU
#then the expected output is
#Total price: $150.53

#Alternatively, if the input is
#Please enter the number of different stocks that you want to purchase: 2 KIRK TSLA
#then the expected output is
#Total price: $921.58


PRACTICE CODE: TALK ABOUT THIS ONE 
stocks = {'TSLA': 912.86, 'BBBY': 24.84, 'AAPL': 174.26, 'SOFI': 6.92, 'KIRK': 8.72, 'AURA': 22.12, 'AMZN': 141.28, 'EMBK': 12.29, 'LVLU': 2.33}

print("Enter a quantity of stocks followed  by stock symbol(s):")

num_items = int(input())

total_price = 0.0 

#loop and calculations 
for i in range(num_items): 
    stock_name = input()
    total_price += stocks[stock_name]
print(f"Total price: ${total_price:.2f}")
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Create a solution that accepts a string input representing a grocery store item and an integer 
#input identifying the number of items purchased on a recent visit. The following dictionary purchase lists 
#available items as the key and the cost per item as the value.
#purchase = {"bananas": 1.85, "steak": 19.99, "cookies": 4.52, "celery": 2.81, "milk": 4.34}
#Additionally,
#If fewer than 10 items are purchased, the price is the full cost per item.
#If between 10 and 20 items (inclusive) are purchased, the purchase gets a 5% discount.
#If 21 or more items are purchased, the purchase gets a 10% discount.
#Output the chosen item and the total purchase cost to two decimal places.
#The solution output should be in the format:
#quantity item_purchased total cost: $total_purchase_cost
 
#Sample Input and Output:
#If the input is
#bananas 12
#then the expected output is
#12 bananas total cost: $21.09

#Alternatively, if the input is
#cookies 144
#then the expected output is
#144 cookies total cost $585.79
#open_in_new

#CODE PRACTICE 
purchase = {"bananas": 1.85, "steak": 19.99, "cookies": 4.52, "celery": 2.81, "milk": 4.34}

# accept inputs
print("Enter the item to purchase:")
item = input()
print("Enter the quantity of that item:")
quantity = int(input())

# base price
cost_per_item = purchase[item]

# apply discount
if quantity < 10:
    total = cost_per_item * quantity
elif 10 <= quantity <= 20:
    total = cost_per_item * quantity * 0.95   # 5% discount
else:
    total = cost_per_item * quantity * 0.90   # 10% discount

# output
print(f"{quantity} {item} total cost: ${total:.2f}")
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Write a Python program that performs the following steps:
#Prompt the user to input the name of a text file (e.g., "WordTextFile.txt").
#The input file contains exactly three rows, each containing a single word.
#Using the open() function and the read() and write()methods, perform the following actions:

#Read the three words from the file.
#Construct a new sentence by combining these words in the same order, separating the words by spaces.
#Append this sentence to the end of the file on a new line. (.Append)
#Display the updated contents of the file.
#Requirements:
#Use the open() function in the appropriate mode to read and write to the file.
#Ensure the words in the sentence are separated by a single space.
#Output the complete updated contents of the file, showing the original words followed by the newly appended sentence.
#Output Format:
#The program should print the updated file contents, with the original words on separate lines and the new sentence on a new line.
 
#Sample Input and Output:
#If the input is
#Enter the name of the input file: WordTextFile.txt
#Contents of WordTextFile.txt before the program runs:
#cat chases dog
#then the expected output is
#cat chases dog cat chases dog  

#solution accepts file input to insert sentence composed of file content into text file on a new line
#solution outputs the text file contents including the new sentence
#accept input identifying filename
print("Enter the name of the input file:")
filename = input()

# read words
with open(filename, "r") as file:
    words = file.read().split()

# build sentence
sentence = " ".join(words)

# append sentence
with open(filename, "a") as file:
    file.write("\n" + sentence)

# read updated file
with open(filename, "r") as file:
    updated = file.read()

# print exactly as expected
print(updated)


-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Write a Python program that performs the following steps:
#Prompt the user to input the name of a CSV file ("input1.csv").
#Use Python's built-in csv module to open and read the specified file.
#For each row in the file, reverse the order of elements (values separated by commas).
#Print the reversed elements for each row to the console.
#Requirements:
#Use the open() function to open the file.
#Use the csv.reader() method to read the file contents.
#Use a loop to iterate through each row and reverse the elements in the row.
#Print the reversed elements as a list for each row.
 
#Sample Input and Output:
#If the input is
#Enter the name of the file along with its extension: input1.csv  
#Contents of input1.csv:
#apple, banana, orange, peach football, soccer, volleyball pizza, burger, sandwich, fries WGU United States, Canada

#Then the expected output is
#['peach', 'orange', 'banana', 'apple'] ['volleyball', 'soccer', 'football'] ['fries', 'sandwich', 'burger', 'pizza'] ['WGU'] ['Canada', 'United States']
#Hints: Use Python's [::-1] slicing technique to reverse a list.

#PRACTICE CODE 
import csv

print("enter the name of the file along with its extension:")
filename = input()

with open(filename , newline= '') as file:
    reader = csv.reader(file)
    for row in reader: 
        row.reverse()
        print(row)



# PRACTICE for reverse code

while True: 
    line_of_text = input()

    if line_of_text.lower() in ("done", "d"): 
        break 
    print(line_of_text[::-1])
-------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Write a program that accepts two integer inputs from the user:
#the number for which the factorial needs to be calculated
#a number to compare the factorial result against
#Use the built-in math module and its factorial() method to compute the factorial of the first input. Then, compare the computed factorial with the second input and output the following:
#the factorial value of the first input
#a Boolean value that indicates whether the factorial value is greater than the second input
#The solution output should be in the format
#The factorial value of number is factorial_value Boolean_value
 
#Sample Input and Output:
#If the input is
#6 500
#then the expected output is
#The factorial value of 6 is 720 True

#Alternatively, if the input is
#4 50
#then the expected output is
#The factorial value of 4 is 24 False

#PRACTICE CODE 

import math

# accept inputs
print("Enter a number to calculate its factorial:")
factorial_num = int(input())
print("Enter a number to compare with the factorial:")
comparison_num = int(input())

# compute factorial
factorial_value = math.factorial(factorial_num)

# compare factorial to second input
is_greater = factorial_value > comparison_num

# output
print(f"The factorial value of {factorial_num} is {factorial_value}")
print(is_greater)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Write a Python program that performs the following steps:
#Accept an integer input representing the age of a pig (in years).
#Import the pre-existing module pigAge.
#Use the built-in function pigAge_converter() from the module to calculate the human-equivalent age of the pig.
#Note: One year of a pig’s life is equivalent to five human years.
#Output the result in the given format where:
#input_pig_age is the pig's age in years.
#converted_pig_age is the human-equivalent age of the pig.
#The solution output should be in the format:
#input_pig_age pig years is equivalent to converted_pig_age in human years
 
#Sample Input and Output:
#If the input is
#8
#then the expected output is
#8 pig years is equivalent to 40 in human years

#PRACTICE CODE 
import pigAge

print("Enter the age of the pig in years:")
input_pigage = int(input())

human_years = pigAge.pigAge_converter(input_pigage)

print(f"{input_pigage} pig years is equivalent to {human_years} in human years")

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: