-4

I wanted to make my friend's birthday a little special, but when I called bb() and after typing in the inputs, the output of the code does not print even though I already created a place holder for the input function.

def bb():
bday = ''
bday = input("Is Today Your Birthday ?"(Yes,No))
if bday == Yes:
    print("          __ __  ____  ____   ___                               
                     |  |  ||    \|    \ |   \                              
                     |  |  ||  o  )  o  )|    \                             
                     |  _  ||   _/|     ||  D  |                            
                     |  |  ||  |  |  O  ||     |                            
                     |  |  ||  |  |     ||     |                            
                     |__|__||__|  |_____||_____|                            
                                                   
                 __  _  __ __   ____  ____   __ __ 
                |  |/ ]|  |  | /    ||    \ |  |  |
                |  ' / |  |  ||  o  ||  _  ||  |  |
                |    \ |  _  ||     ||  |  ||  _  |
                |     ||  |  ||  _  ||  |  ||  |  |
                |  .  ||  |  ||  |  ||  |  ||  |  |
                |__|\_||__|__||__|__||__|__||__|__|
                                                    ")
  • 1
    Can you ensure the snippet you've pasted here is *exactly* as you've got it in your IDE? Your indentation is a bit awry from what it seems you're trying to do, and the line `bday = input("Is Today Your Birthday ?"(Yes,No))` should throw several errors when interpreted. – esqew Mar 04 '21 at 03:12
  • 1
    You should 1. Fix indent 2. Remove yes no in input or move into string 3. Make Yes "Yes" 4. Use """ """ if you want to use new line within string. – MarkSouls Mar 04 '21 at 03:15
  • See below for indentation and `input` issue as pointed out by both @esqew and @MarkSouls – astrochun Mar 04 '21 at 03:16
  • Yes, thank you but after fixing the "yes" it still has "SyntaxError: EOL while scanning string literal" and does not print the image – Newyen minh Mar 04 '21 at 03:17
  • You haven't properly quoted your string as multiline with the `"""` delimiter - regular Python strings (delimited by `"`) cannot span multiple lines (as your interpreter just alerted you). [Related SO question](https://stackoverflow.com/questions/10660435/pythonic-way-to-create-a-long-multi-line-string). – esqew Mar 04 '21 at 03:18
  • Right, the triple quote is needed here. Though I agree, that you should have a `multiline_str` variable to pass in would be more elegant and you would not need to deal with indentation. – astrochun Mar 04 '21 at 03:34
  • Ahhh right, thank you, everyone, for your help, I am a beginner sorry for this silly question – Newyen minh Mar 04 '21 at 03:39
  • I've revised my answer. This should work without any indentation issue. Perhaps a better way is to ask for month and day and determine using `datetime` whether that is today. Then print the message. – astrochun Mar 04 '21 at 03:48

2 Answers2

0

Mistakes you have made

  1. input() function of python will take a prompt message which should be a string
  2. input function will give a string from the user input so when you check the result of the input function you should use string comparison
  3. you use multiline to print. For that, you need to use """
  4. when you define the things under the function you should invoke the function.
def bb():
   bday = input("Is Today Your Birthday ? (Yes,No)")
   if bday == "Yes":
      print("""          __ __  ____  ____   ___                               
                     |  |  ||    \|    \ |   \                              
                     |  |  ||  o  )  o  )|    \                             
                     |  _  ||   _/|     ||  D  |                            
                     |  |  ||  |  |  O  ||     |                            
                     |  |  ||  |  |     ||     |                            
                     |__|__||__|  |_____||_____|                            
                                                   
                 __  _  __ __   ____  ____   __ __ 
                |  |/ ]|  |  | /    ||    \ |  |  |
                |  ' / |  |  ||  o  ||  _  ||  |  |
                |    \ |  _  ||     ||  |  ||  _  |
                |     ||  |  ||  _  ||  |  ||  |  |
                |  .  ||  |  ||  |  ||  |  ||  |  |
                |__|\_||__|__||__|__||__|__||__|__|
                                                    """)
bb()

enter image description here

Sivaram Rasathurai
  • 5,533
  • 3
  • 22
  • 45
-2

Here's a revision to you code for indentation and to fix a few errors.

I put your message in a block quote so it's easier to change:

Note that bday is a string, so to get an exact match, you need to do a str to str match (bday == 'Yes'):

message = """
  __ __  ____  ____   ___                               
 |  |  ||    \|    \ |   \                              
 |  |  ||  o  )  o  )|    \                             
 |  _  ||   _/|     ||  D  |                            
 |  |  ||  |  |  O  ||     |                            
 |  |  ||  |  |     ||     |                            
 |__|__||__|  |_____||_____|                            
  __  _  __ __   ____  ____   __ __ 
 |  |/ ]|  |  | /    ||    \ |  |  |
 |  ' / |  |  ||  o  ||  _  ||  |  |
 |    \ |  _  ||     ||  |  ||  _  |
 |     ||  |  ||  _  ||  |  ||  |  |
 |  .  ||  |  ||  |  ||  |  ||  |  |
 |__|\_||__|__||__|__||__|__||__|__|
"""

def bb():
    bday = input("Is Today Your Birthday ? (Yes,No) ")
    if bday == 'Yes':
        print(message)


bb()

Output:

python test.py
Is Today Your Birthday ? (Yes,No) Yes

  __ __  ____  ____   ___                               
 |  |  ||    \|    \ |   \                              
 |  |  ||  o  )  o  )|    \                             
 |  _  ||   _/|     ||  D  |                            
 |  |  ||  |  |  O  ||     |                            
 |  |  ||  |  |     ||     |                            
 |__|__||__|  |_____||_____|                            
  __  _  __ __   ____  ____   __ __ 
 |  |/ ]|  |  | /    ||    \ |  |  |
 |  ' / |  |  ||  o  ||  _  ||  |  |
 |    \ |  _  ||     ||  |  ||  _  |
 |     ||  |  ||  _  ||  |  ||  |  |
 |  .  ||  |  ||  |  ||  |  ||  |  |
 |__|\_||__|__||__|__||__|__||__|__|

astrochun
  • 1,642
  • 2
  • 7
  • 18