Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
walrus operator
=) in Python:# Walrus operator example
while (user_input := input("Enter 'q' to quit: ")) != 'q':
print("You entered:", user_input)
:=
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.opogagawa ng program ?
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.")
meron na po sa classmate ko to huhuPython: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.
opo huhu 37 po kasi kami kaya kailangan unique talagaahh dapat ba iba iba hahaha.
yung sa grade sa subject, days, weather, ageano ano ba meron na para maiwasan hahah
wala pobooks wala pa ?
wala po
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}")
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?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)
panong dalawa ? dalawang condition ? o sa loob ng elif may if (nested if)?pwede naman po gawing dalawa lang yunh elif no?
dalawanh elif condition lang popanong dalawa ? dalawang condition ? o sa loob ng elif may if (nested if)?
ahhdalawanh elif condition lang po
dalawanh elif condition lang popanong dalawa ? dalawang condition ? o sa loob ng elif may if (nested if)?
ano pong function ng .lower?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)
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 paytondalawanh elif condition lang po
ano pong function ng .lower?
so automatic na mag small caps yung input nila?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
may iba ka pa po na maiikli langPython: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)