Day 008 - Project 8 : Affirmations (or insults) Generator

Thank you so much CoderElijah for suggesting the new method. I will try it.

No, not school assignments. I was just referring to the challenges posted for each day of the course. I am just trying to figure out what the best way to check if the python code I came up with is correct or not.

1 Like

[100 Days Of Code] Day 8
This is mostly a note for me to keep me motivated for 100 days
Day 8- Day 8 went pretty well I am still enjoying doing this course of 100 days of code and can’t wait to get to day 100! I love this because even though I’m still doing stuff I already know how to enjoy redoing it. It’s been a lot of fun and I am ready to keep going!

Replit- https://replit.com/@Chandler0Bing/100-Days-Of-Code-Day-8

Question:
hi! I’m currently doing the 100 days of python course and I have to create an affirmation generator. for some reason, when I type in ‘sabine’ ‘tuesday’ ‘great’ the output for monday is coming. with ‘sabine’ ‘tuesday’ ‘good’ the tuesday output is coming. I must have used the or-statement wrong, but I don’t know what to change

code snippet

Name = input ("What's your name?")
Day = input ("What day of the week is it?")
Feeling = input ("How are you feeling?")
if Name == "Sabine" or Name == "sabine" and Day == "Monday" or Day == "monday" and Feeling == "good" or  Feeling == "Good" or Feeling == "great":
  print ("Sabine just starting the week with that positive ernegy, amazing! You'll rock this week for sure!")
elif Name == "Sabine" or Name == "sabine" and Day == "Monday" or Day == "monday" and Feeling == "bad" or Feeling == "tired":
  print('''Monday is the hardest day of the week, 
  but also just it's beginning! Take a moment for yourself, 
  drink a coffee and remember that you just gotta find the right attitude to rock it!''')
elif Name == "Sabine" or Name == "sabine" and Day == "Tuesday" or Day == "tuesday" and Feeling == "good" or Feeling == "Good" or Feeling == "great":
  print ("whoop whoop sabine feeling good and looking awesome!")

Hi @sabinedaams , welcome to the forums!
What if you change all the ors to ands?
Does that work?

Hello! I don’t think so, because I don’t want that the user has to say he is feeling ‘good, Good, great’. I just want that it doesn’t matter if he’s saying good, Good or great, the answer will occur either way. That’s why I used or, just one condition has to be true for the statement to be true.

1 Like

As I remember, python process “and” before “or”, correct me if this isn’t true

Try bracketing the statements, such like

To
if (Name == "Sabine" or Name == "sabine" )and (Day == "Monday" or Day == "monday") and (Feeling == "good" or Feeling == "Good" or Feeling == "great"):

2 Likes

Hi @sabinedaams !
Could you try this:

Name = input ("What's your name?")
Day = input ("What day of the week is it?")
Feeling = input ("How are you feeling?")
if Name == "Sabine" or Name == "sabine":
  if Day == "Monday" or Day == "monday":
    if Feeling == "good" or  Feeling == "Good" or Feeling == "great":
      print ("Sabine just starting the week with that positive ernegy, amazing! You'll rock this week for sure!")
    elif Feeling == "bad" or Feeling == "tired":
      print('''Monday is the hardest day of the week, 
  but also just it's beginning! Take a moment for yourself, 
  drink a coffee and remember that you just gotta find the right attitude to rock it!''')
  elif Day == "Tuesday" or Day == "tuesday" :
    if Feeling == "good" or Feeling == "Good" or Feeling == "great":
      print ("whoop whoop sabine feeling good and looking awesome!")

I believe this should work. If it doesn’t, please tell me!

Thank you!!! We didn’t learn about brackets in the course yet, I don’t know why that’s so helpful! :slight_smile:

Hi @sabinedaams !
Could you try my code? It could be a simpler alternative.

that also works!! thank you so much :slight_smile:

1 Like

By the way, in python brackets can be used like how it is used in math, it prioritises the thing inside to be processed first.

2 Likes

In my code, you first check if the name in Sabine.
Then, you check if the day is Monday. If it is, you check if the feeling is good or bad, and a statement is printed based on the feeling.
Returning back to the day check, if it’s Tuesday, check if the feeling is good.
If it is, a happy message is displayed.

totally, your code is more elegant than mine! Thanks both of you! Now I know how to solve my problem with brackets and a better way to write the code :slight_smile:

1 Like

We’re glad to help you!
Do come back again if you have other questions!

1 Like

Make the code even simpler with case-insensitive input (the norm), and in operators.

Name = input("What's your name?").lower()
Day = input("What day of the week is it?").lower()
Feeling = input("How are you feeling?").lower()
if Name == "sabine":
  if Day == "monday":
    if Feeling in ("good","great"):
      print("Sabine just starting the week with that positive energy, amazing! You'll rock this week for sure!")
    elif Feeling in ("bad","tired"):
      print('''Monday is the hardest day of the week, 
  but also just it's beginning! Take a moment for yourself, 
  drink a coffee and remember that you just gotta find the right attitude to rock it!''')
  elif Day == "tuesday":
    if Feeling in ("good","great"):
      print("whoop whoop sabine feeling good and looking awesome!")
2 Likes

https://replit.com/@DylanMonks/day-8-100-days

Welcome to Ask! The syntax error on line 10 is actually caused by a missing ) on line 9. Adding that should fix your problem. :slightly_smiling_face:

3 Likes

Hi! When I run my code and enter Sunday I do not get the correct print statement instead the print statement for the else statement prints out. Does anyone know what I could be missing?
https://replit.com/@StaceyGraham/day-8-100-days

:wave: Welcome @StaceyGraham!

Lines 14 and 15 are indented too much. Simply unindent them by highlighting and pressing Shift + Tab

1 Like