0

I'm trying to write a little horoscope program that takes in a zodiac sign as an input and runs through a series of other questions that also require input. I'm struggling to figure out why the elif and else statements are not working. Here's my code.

import requests
import textwrap as tr

# yesterday = "http://sandipbgt.com/theastrologer/api/horoscope/{sunsign}/yesterday"
# tomorrow = "http://sandipbgt.com/theastrologer/api/horoscope/{sunsign}/tomorrow"
# today = "http://sandipbgt.com/theastrologer/api/horoscope/{sunsign}/today"
# sunsign_list = "http://sandipbgt.com/theastrologer/api/horoscope/{sunsign}/sunsigns"

signs = requests.get("http://sandipbgt.com/theastrologer/api/sunsigns").json()

sign_dates = {'Aries:': 'March 21 - April 19', 'Taurus:': 'April 20 – May 20', 'Gemini:': 'May 21 – June 20', 'Cancer:': 'June 21 – July 22', 'Leo:': 'July 23 – August 22', 'Virgo:': 'August 23 – September 22', 'Libra:': 'September 23 – October 22', 'Scorpio:': 'October 23 – November 21', 'Sagittarius:': 'November 22 – December 21', 'Capricorn:': 'December 22 – January 19', 'Aquarius:': 'January 20 – February 18', 'Pisces:': 'February 19 – March 20'}

i = 1

while i == 1:
    input("Are you ready to check out your horoscope? \n\n"
          "Please enter 'yes' or 'no'. ")

    if input == 'yes' or 'Yes' or 'YES':
        print('Okay cool! check out the list of zodiac signs and their corresponding dates below! ')
        print('Zodiac sign list below: ')
        print('')

        for key, value in sign_dates.items():
            print(key, value)

        '''another method to print the key, value pairs of sign_date dictionary.
    result = '\n'.join(f'{key}: {value}' for key, value in sign_dates.items())
    print(result)'''

        selectedSign = input('\nWhat sign are you?:\n')

        timeframe = input("Do you want your horoscope for 'today', 'tomorrow', or 'yesterday'? ")

        horoscope = requests.get(f"http://sandipbgt.com/theastrologer/api/horoscope/{selectedSign}/{timeframe}").json()
        print(str(horoscope))

        input('Pretty cool huh?\n\n'
              'Would you like to check another timeframe or check another zodiac sign? ')

        if input == 'yes' or 'Yes' or 'YES':
            print('Okay cool! Sending you to main menu:')
            i = 1

        elif input != 'yes' or 'Yes' or 'YES':
            print('Okay! Have a good one!')
            break

    elif input == 'no' or 'No' or 'NO':
        print('Okay! Have a good one!')
        break

    else:
        print('Oops! Something went wrong. Please try again!')
        i = 1

The elif and else statements are not working and they are ignored. Also, the if and elif statements within the most outer if statement don't work properly as well. I could enter in a no for the inputs and the program is still running through the most outer if statement flow. Would anyone be able to give me some advice on how I could fix this? Thank you, I appreciate it.

I tried entering yes when prompted to answer the first input question and it works fine except for when I reach the if, elif statements within the most outer if statement.

I tried entering no and a random input when prompted to answer the first input question and the program still acts as if I answered yes to the original input question.

  • Check out what 'a' or 'b' is in python. You are asking if a string is equal to a Boolean. Your if clause will never trigger. Use the in keyword instead. – jlandercy Nov 03 '22 at 21:41
  • All of your if statements reference `input`, which would just call the built-in function. `>>> input `. Instead, you want something like `input_data = intput('your question')` and then use `input_data` in the if statement – Zach J. Nov 03 '22 at 21:44
  • I tried assigned the input to a variable and then used the variable in the if statement and it still didn't work. I also tried this: if input_data == str('yes'): and that didn't work either. jlandercy, I'm not too sure what you mean? – trashpanda Nov 04 '22 at 14:14
  • I used the in keyword like you said and it worked. I said, if input_data in {'yes', 'Yes', 'YES'}: That worked. Thanks jlandercy – trashpanda Nov 04 '22 at 14:20

0 Answers0