What's new

Help Pa help po python

woodvale

Addict
Joined
Jul 18, 2021
Posts
349
Reaction
107
Points
117
kayo na po bahala basta yung madali lang i-explain and hindi masyadong common. pang recitation lanh po. thank youuuuu

ito po syntax



20240321_083401.jpg
 

Attachments

Hello! Sure, I'd be happy to help you with a simple and not-too-common Python syntax for recitation purposes. Here is an example of the walrus operator :)=) in Python:

Python:
# Walrus operator example
while (user_input := input("Enter 'q' to quit: ")) != 'q':
    print("You entered:", user_input)

In this example, the walrus operator := is used to both assign the value of input("Enter 'q' to quit: ") to the variable user_input and check if it is not equal to 'q' in the while loop condition. This operator helps in writing more concise and readable code by combining assignment and comparison in a single expression.

Feel free to ask if you have any questions or need further explanation!
 
Python:
age = int(input("Please enter your age: "))

if age < 13:
    print("You are a child.")
elif age >= 13 and age <= 19:
    print("You are a teen.")
elif age >= 20 and age <= 39:
    print("You are a young ãdül†.")
elif age >= 40 and age <= 59:
    print("You are an ãdül†.")
elif age >= 60:
    print("You are a senior.")
else:
    print("Invalid age.")


sample code na checking lang ng age.
 
Python:
age = int(input("Please enter your age: "))

if age < 13:
    print("You are a child.")
elif age >= 13 and age <= 19:
    print("You are a teen.")
elif age >= 20 and age <= 39:
    print("You are a young ãdül†.")
elif age >= 40 and age <= 59:
    print("You are an ãdül†.")
elif age >= 60:
    print("You are a senior.")
else:
    print("Invalid age.")


sample code na checking lang ng age.
meron na po sa classmate ko to huhu
 
Python:
def recommend_book(genre):
    if genre.lower() == 'fantasy':
        return "The Hobbit by J.R.R. Tolkien"
    elif genre.lower() == 'science fiction':
        return "Dune by Frank Herbert"
    elif genre.lower() == 'mystery':
        return "The Big Sleep by Raymond Chandler"
    elif genre.lower() == 'romance':
        return "Pride and Prejudice by Jane Austen"
    elif genre.lower() == 'horror':
        return "Dracula by Bram Stoker"
    elif genre.lower() == 'thriller':
        return "The Girl with the Dragon Tattoo by Stieg Larsson"
    elif genre.lower() == 'nonfiction':
        return "Sapiens by Yuval Noah Harari"
    else:
        return "The Great Gatsby by F. Scott Fitzgerald, a classic for any taste!"

genre = input("What is your favorite book genre? (e.g., fantasy, science fiction, mystery, romance, horror, thriller, nonfiction): ")

book_recommendation = recommend_book(genre)
print(f"We recommend you read: {book_recommendation}")

eto pa HAHAHA

mood naman

Python:
def mood_response(mood):
    if mood.lower() == 'happy':
        return "It's wonderful to see you so joyful! 😊"
    elif mood.lower() == 'sad':
        return "Sending you a virtual hug. Things will get better! 🤗"
    elif mood.lower() == 'angry':
        return "Take a deep breath. Let's channel that energy positively! 💪"
    elif mood.lower() == 'excited':
        return "That's fantastic! I hope everything turns out great! 🎉"
    elif mood.lower() == 'nervous':
        return "It's okay to feel that way. I believe in you! 🌟"
    elif mood.lower() == 'tired':
        return "Remember to rest. You deserve a break. 😴"
    else:
        return "I'm not sure what to say, but I'm here for you! 🌈"

mood = input("How are you feeling right now? (happy, sad, angry, excited, nervous, tired) ")

personalized_message = mood_response(mood)
print(personalized_message)
 
Python:
def recommend_book(genre):
    if genre.lower() == 'fantasy':
        return "The Hobbit by J.R.R. Tolkien"
    elif genre.lower() == 'science fiction':
        return "Dune by Frank Herbert"
    elif genre.lower() == 'mystery':
        return "The Big Sleep by Raymond Chandler"
    elif genre.lower() == 'romance':
        return "Pride and Prejudice by Jane Austen"
    elif genre.lower() == 'horror':
        return "Dracula by Bram Stoker"
    elif genre.lower() == 'thriller':
        return "The Girl with the Dragon Tattoo by Stieg Larsson"
    elif genre.lower() == 'nonfiction':
        return "Sapiens by Yuval Noah Harari"
    else:
        return "The Great Gatsby by F. Scott Fitzgerald, a classic for any taste!"

genre = input("What is your favorite book genre? (e.g., fantasy, science fiction, mystery, romance, horror, thriller, nonfiction): ")

book_recommendation = recommend_book(genre)
print(f"We recommend you read: {book_recommendation}")

eto pa HAHAHA

mood naman

Python:
def mood_response(mood):
    if mood.lower() == 'happy':
        return "It's wonderful to see you so joyful! 😊"
    elif mood.lower() == 'sad':
        return "Sending you a virtual hug. Things will get better! 🤗"
    elif mood.lower() == 'angry':
        return "Take a deep breath. Let's channel that energy positively! 💪"
    elif mood.lower() == 'excited':
        return "That's fantastic! I hope everything turns out great! 🎉"
    elif mood.lower() == 'nervous':
        return "It's okay to feel that way. I believe in you! 🌟"
    elif mood.lower() == 'tired':
        return "Remember to rest. You deserve a break. 😴"
    else:
        return "I'm not sure what to say, but I'm here for you! 🌈"

mood = input("How are you feeling right now? (happy, sad, angry, excited, nervous, tired) ")

personalized_message = mood_response(mood)
print(personalized_message)
pwede naman po gawing dalawa lang yunh elif no?
 
panong dalawa ? dalawang condition ? o sa loob ng elif may if (nested if)?
dalawanh elif condition lang po
Python:
def recommend_book(genre):
    if genre.lower() == 'fantasy':
        return "The Hobbit by J.R.R. Tolkien"
    elif genre.lower() == 'science fiction':
        return "Dune by Frank Herbert"
    elif genre.lower() == 'mystery':
        return "The Big Sleep by Raymond Chandler"
    elif genre.lower() == 'romance':
        return "Pride and Prejudice by Jane Austen"
    elif genre.lower() == 'horror':
        return "Dracula by Bram Stoker"
    elif genre.lower() == 'thriller':
        return "The Girl with the Dragon Tattoo by Stieg Larsson"
    elif genre.lower() == 'nonfiction':
        return "Sapiens by Yuval Noah Harari"
    else:
        return "The Great Gatsby by F. Scott Fitzgerald, a classic for any taste!"

genre = input("What is your favorite book genre? (e.g., fantasy, science fiction, mystery, romance, horror, thriller, nonfiction): ")

book_recommendation = recommend_book(genre)
print(f"We recommend you read: {book_recommendation}")

eto pa HAHAHA

mood naman

Python:
def mood_response(mood):
    if mood.lower() == 'happy':
        return "It's wonderful to see you so joyful! 😊"
    elif mood.lower() == 'sad':
        return "Sending you a virtual hug. Things will get better! 🤗"
    elif mood.lower() == 'angry':
        return "Take a deep breath. Let's channel that energy positively! 💪"
    elif mood.lower() == 'excited':
        return "That's fantastic! I hope everything turns out great! 🎉"
    elif mood.lower() == 'nervous':
        return "It's okay to feel that way. I believe in you! 🌟"
    elif mood.lower() == 'tired':
        return "Remember to rest. You deserve a break. 😴"
    else:
        return "I'm not sure what to say, but I'm here for you! 🌈"

mood = input("How are you feeling right now? (happy, sad, angry, excited, nervous, tired) ")

personalized_message = mood_response(mood)
print(personalized_message)
ano pong function ng .lower?
 
para ma control mo yung input ni user. kase baka all caps i input nya d mag match sa condition mo kase. case sensitive ang payton
so automatic na mag small caps yung input nila?

Python:
def recommend_book(genre):
    if genre.lower() == 'fantasy':
        return "The Hobbit by J.R.R. Tolkien"
    elif genre.lower() == 'science fiction':
        return "Dune by Frank Herbert"
    elif genre.lower() == 'mystery':
        return "The Big Sleep by Raymond Chandler"
    elif genre.lower() == 'romance':
        return "Pride and Prejudice by Jane Austen"
    elif genre.lower() == 'horror':
        return "Dracula by Bram Stoker"
    elif genre.lower() == 'thriller':
        return "The Girl with the Dragon Tattoo by Stieg Larsson"
    elif genre.lower() == 'nonfiction':
        return "Sapiens by Yuval Noah Harari"
    else:
        return "The Great Gatsby by F. Scott Fitzgerald, a classic for any taste!"

genre = input("What is your favorite book genre? (e.g., fantasy, science fiction, mystery, romance, horror, thriller, nonfiction): ")

book_recommendation = recommend_book(genre)
print(f"We recommend you read: {book_recommendation}")

eto pa HAHAHA

mood naman

Python:
def mood_response(mood):
    if mood.lower() == 'happy':
        return "It's wonderful to see you so joyful! 😊"
    elif mood.lower() == 'sad':
        return "Sending you a virtual hug. Things will get better! 🤗"
    elif mood.lower() == 'angry':
        return "Take a deep breath. Let's channel that energy positively! 💪"
    elif mood.lower() == 'excited':
        return "That's fantastic! I hope everything turns out great! 🎉"
    elif mood.lower() == 'nervous':
        return "It's okay to feel that way. I believe in you! 🌟"
    elif mood.lower() == 'tired':
        return "Remember to rest. You deserve a break. 😴"
    else:
        return "I'm not sure what to say, but I'm here for you! 🌈"

mood = input("How are you feeling right now? (happy, sad, angry, excited, nervous, tired) ")

personalized_message = mood_response(mood)
print(personalized_message)
may iba ka pa po na maiikli lang
 

Similar threads

Back
Top