Python Errors With Terminal (MAC)

Hello fellow mac python users I have a serious question for you.

When i type the code below it gives me like 100 error messages with my code broken up and I have not idea why!:
Code 1:



# -*- coding: utf-8 -*-
def hotel_cost(days):
    return 140 * days
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    elif city == "Tampa":
        return 220
    elif city == "Pittsburgh":
        return 222
    elif city == "Los Angeles" or answer == "LA":
        return 475
    else:
        return "City not in database, please try again”
def rental_car_cost(days):
    cost = 40 * days
    if days >= 7:
        cost -= 50
        return cost
    elif days >= 3:
        cost -= 20
    return cost
def trip_cost(city, days, spendmoney):
    return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days) + spendmoney
print (trip_cost("Los Angeles", 5, 600))


However is I use this code:



# -*- coding: utf-8 -*-
def House():
    print "Hello Mister Welcome To Your House "
    print "Do you go to the bedroom or bathroom or kitchen?"
    answer = raw_input("Type bedroom or bathroom or kitchen and hit 'Enter'.").lower()
    if answer == "bedroom" or answer == "bed":
        print "This is your bedroom, and what is that!"
        print "Do you go to sleep or clean up?"
        answer = raw_input("Type clean up or sleep and hit 'Enter'.").lower()
        if answer == "sleep" or answer == "good night":
            print "Zzzzzz"
            print "Do you wake up or still sleep?"
            answer = raw_input("Type wake up or sleep and hit 'Enter'.").lower()
            if answer == "sleep" or answer == "good night":
                print "Jeez your super lazy! Good Bye Forever!"
            elif answer == "wake up" or answer == "wake":
                print "YAAWWWNNN"
                print "Do you go to the bathroom or kitchen?"
                answer = raw_input("Type bathroom or kitchen and hit 'Enter'.").lower()
                if answer == "bathroom" or answer == "bath":
                        print "Oh god the bathroom is dirty!"
                        print "Do you use it or clean up?"
                        answer = raw_input("Type use it or clean up and hit 'Enter'.").lower()
                        if answer == "clean up" or answer == "clean":
                            print "WOW that was tough!"
                            print "Do you need to go?"
                            answer = raw_input("Type Yes or No and hit 'Enter'.").lower()
                            if answer == "Yes" or answer == "yes":
                                print "Number 1 or 2?"
                                answer = raw_input("Type 1 or 2 and hit 'Enter'.").lower()
                                if answer == "1":
                                    print "PEEEEEEE"
                                elif answer == "2":
                                    print "POOOOOO"
                            elif answer == "No" or answer == "no":
                                print "Ok"
                        elif answer == "use it" or answer == "use":
                                print "Ewww whats that!"
                                print "Your to lazy! So you fell asleep and were robbed in your sleep on the toliet!"
                elif answer == "kitchen" or answer == "cook":
                        print "Look At The DISHES!"
                        print "Do you cook or clean up?"
                        answer = raw_input("Type cook or clean up and hit 'Enter'.").lower()
                        if answer == "cook" or answer == "use":
                                print "What do you want to cook?"
                                answer = raw_input("Type Pizza or Apple Sauce and hit 'Enter'.").lower()
                                if answer == "Pizza" or answer == "pizza":
                                        print "OH MY, YOU GOT A HEART ATTACK AND DIED!!!"
                                elif answer == "Apple Sause" or answer == "apple sauce":
                                        print "Nice Healthy Decsion!"
                        elif answer == "Clean Up" or answer == "clean up":
                                print "Wow thats tiring!"
                                print "Lets go to sleep"
                                print "Do you want to sleep more or wake up?"
                                answer = raw_input("Type wake up or sleep and hit 'Enter'.").lower()
                                if answer == "sleep" or answer == "good night":
                                            print "Jeez your super lazy! Good Bye Forever!"
                                elif answer == "wake up" or answer == "wake":
                                            print "YAAWWWNNN"
                                            print "Good You Lived A Long Life!"
    elif answer == "bathroom" or answer == "bath":
        print "Oh god the bathroom is dirty!"
        print "Do you use it or clean up?"
        answer = raw_input("Type use it or clean up and hit 'Enter'.").lower()
        if answer == "clean up" or answer == "clean":
            print "WOW that was tough!"
            print "Do you need to go?"
            answer = raw_input("Type Yes or No and hit 'Enter'.").lower()
            if answer == "Yes" or answer == "yes":
                    print "Number 1 or 2?"
                    answer = raw_input("Type 1 or 2 and hit 'Enter'.").lower()
                    if answer == "1":
                            print "PEEEEEEE"
                    elif answer == "2":
                            print "POOOOOO"
            elif answer == "No" or answer == "no":
                    print "Ok"
        elif answer == "use it" or answer == "use":
            print "Ewww whats that!"
            print "Your to lazy! So you fell asleep and were robbed in your sleep on the toliet!"
    elif answer == "kitchen" or answer == "cook":
        print "Look At The DISHES!"
        print "Do you cook or clean up?"
        answer = raw_input("Type cook or clean up and hit 'Enter'.").lower()
        if answer == "cook" or answer == "use":
            print "What do you want to cook?"
            answer = raw_input("Type Pizza or Apple Sauce and hit 'Enter'.").lower()
            if answer == "Pizza" or answer == "pizza":
                    print "OH MY, YOU GOT A HEART ATTACK AND DIED!!!"
            elif answer == "Apple Sause" or answer == "apple sauce":
                    print "Nice Healthy Decsion!"
        elif answer == "Clean Up" or answer == "clean up":
            print "Wow thats tiring!"
            print "Lets go to sleep"
            print "Do you want to sleep more or wake up?"
            answer = raw_input("Type wake up or sleep and hit 'Enter'.").lower()
            if answer == "sleep" or answer == "good night":
                    print "Jeez your super lazy! Good Bye Forever!"
            elif answer == "wake up" or answer == "wake":
                    print "YAAWWWNNN"
                    print "Good You Lived A Long Life!"
    else:
        print "You didn't pick bedroom, bathroom or kitchen! Try again."
        House()

House()


It works.

Why does this happen?

Proof:

Code 1 Once Typed In:


 # -*- coding: utf-8 -*-
... def hotel_cost(days):
...     return 140 * days
... def plane_ride_cost(city):
  File "<stdin>", line 4
    def plane_ride_cost(city):
      ^
SyntaxError: invalid syntax
>>>     if city == "Charlotte":
  File "<stdin>", line 1
    if city == "Charlotte":
    ^
IndentationError: unexpected indent
>>>         return 183
  File "<stdin>", line 1
    return 183
    ^
IndentationError: unexpected indent
>>>     elif city == "Tampa":
  File "<stdin>", line 1
    elif city == "Tampa":
    ^
IndentationError: unexpected indent
>>>         return 220
  File "<stdin>", line 1
    return 220
    ^
IndentationError: unexpected indent
>>>     elif city == "Pittsburgh":
  File "<stdin>", line 1
    elif city == "Pittsburgh":
    ^
IndentationError: unexpected indent
>>>         return 222
  File "<stdin>", line 1
    return 222
    ^
IndentationError: unexpected indent
>>>     elif city == "Los Angeles" or answer == "LA":
  File "<stdin>", line 1
    elif city == "Los Angeles" or answer == "LA":
    ^
IndentationError: unexpected indent
>>>         return 475
  File "<stdin>", line 1
    return 475
    ^
IndentationError: unexpected indent
>>>     else:
  File "<stdin>", line 1
    else:
    ^
IndentationError: unexpected indent
>>>         return "City not in database, please try again”
  File "<stdin>", line 1
    return "City not in database, please try again”
    ^
IndentationError: unexpected indent
>>> def rental_car_cost(days):
...     cost = 40 * days
...     if days >= 7:
...         cost -= 50
...         return cost
...     elif days >= 3:
...         cost -= 20
...     return cost
... def trip_cost(city, days, spendmoney):
  File "<stdin>", line 9
    def trip_cost(city, days, spendmoney):
      ^
SyntaxError: invalid syntax
>>>     return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days) + spendmoney
  File "<stdin>", line 1
    return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days) + spendmoney
    ^
IndentationError: unexpected indent
>>> print (trip_cost("Los Angeles", 5, 600))

Code 2 Once Typed In: (Answers Included!)


>>> # -*- coding: utf-8 -*-
... def House():
...     print "Hello Mister Welcome To Your House "
...     print "Do you go to the bedroom or bathroom or kitchen?"
...     answer = raw_input("Type bedroom or bathroom or kitchen and hit 'Enter'.").lower()
...     if answer == "bedroom" or answer == "bed":
...         print "This is your bedroom, and what is that!"
...         print "Do you go to sleep or clean up?"
...         answer = raw_input("Type clean up or sleep and hit 'Enter'.").lower()
...         if answer == "sleep" or answer == "good night":
...             print "Zzzzzz"
...             print "Do you wake up or still sleep?"
...             answer = raw_input("Type wake up or sleep and hit 'Enter'.").lower()
...             if answer == "sleep" or answer == "good night":
...                 print "Jeez your super lazy! Good Bye Forever!"
...             elif answer == "wake up" or answer == "wake":
...                 print "YAAWWWNNN"
...                 print "Do you go to the bathroom or kitchen?"
...                 answer = raw_input("Type bathroom or kitchen and hit 'Enter'.").lower()
...                 if answer == "bathroom" or answer == "bath":
...                         print "Oh god the bathroom is dirty!"
...                         print "Do you use it or clean up?"
...                         answer = raw_input("Type use it or clean up and hit 'Enter'.").lower()
...                         if answer == "clean up" or answer == "clean":
...                             print "WOW that was tough!"
...                             print "Do you need to go?"
...                             answer = raw_input("Type Yes or No and hit 'Enter'.").lower()
...                             if answer == "Yes" or answer == "yes":
...                                 print "Number 1 or 2?"
...                                 answer = raw_input("Type 1 or 2 and hit 'Enter'.").lower()
...                                 if answer == "1":
...                                     print "PEEEEEEE"
...                                 elif answer == "2":
...                                     print "POOOOOO"
...                             elif answer == "No" or answer == "no":
...                                 print "Ok"
...                         elif answer == "use it" or answer == "use":
...                                 print "Ewww whats that!"
...                                 print "Your to lazy! So you fell asleep and were robbed in your sleep on the toliet!"
...                 elif answer == "kitchen" or answer == "cook":
...                         print "Look At The DISHES!"
...                         print "Do you cook or clean up?"
...                         answer = raw_input("Type cook or clean up and hit 'Enter'.").lower()
...                         if answer == "cook" or answer == "use":
...                                 print "What do you want to cook?"
...                                 answer = raw_input("Type Pizza or Apple Sauce and hit 'Enter'.").lower()
...                                 if answer == "Pizza" or answer == "pizza":
...                                         print "OH MY, YOU GOT A HEART ATTACK AND DIED!!!"
...                                 elif answer == "Apple Sause" or answer == "apple sauce":
...                                         print "Nice Healthy Decsion!"
...                         elif answer == "Clean Up" or answer == "clean up":
...                                 print "Wow thats tiring!"
...                                 print "Lets go to sleep"
...                                 print "Do you want to sleep more or wake up?"
...                                 answer = raw_input("Type wake up or sleep and hit 'Enter'.").lower()
...                                 if answer == "sleep" or answer == "good night":
...                                             print "Jeez your super lazy! Good Bye Forever!"
...                                 elif answer == "wake up" or answer == "wake":
...                                             print "YAAWWWNNN"
...                                             print "Good You Lived A Long Life!"
...     elif answer == "bathroom" or answer == "bath":
...         print "Oh god the bathroom is dirty!"
...         print "Do you use it or clean up?"
...         answer = raw_input("Type use it or clean up and hit 'Enter'.").lower()
...         if answer == "clean up" or answer == "clean":
...             print "WOW that was tough!"
...             print "Do you need to go?"
...             answer = raw_input("Type Yes or No and hit 'Enter'.").lower()
...             if answer == "Yes" or answer == "yes":
...                     print "Number 1 or 2?"
...                     answer = raw_input("Type 1 or 2 and hit 'Enter'.").lower()
...                     if answer == "1":
...                             print "PEEEEEEE"
...                     elif answer == "2":
...                             print "POOOOOO"
...             elif answer == "No" or answer == "no":
...                     print "Ok"
...         elif answer == "use it" or answer == "use":
...             print "Ewww whats that!"
...             print "Your to lazy! So you fell asleep and were robbed in your sleep on the toliet!"
...     elif answer == "kitchen" or answer == "cook":
...         print "Look At The DISHES!"
...         print "Do you cook or clean up?"
...         answer = raw_input("Type cook or clean up and hit 'Enter'.").lower() 
...         if answer == "cook" or answer == "use":
...             print "What do you want to cook?"
...             answer = raw_input("Type Pizza or Apple Sauce and hit 'Enter'.").lower()
...             if answer == "Pizza" or answer == "pizza":
...                     print "OH MY, YOU GOT A HEART ATTACK AND DIED!!!"
...             elif answer == "Apple Sause" or answer == "apple sauce":
...                     print "Nice Healthy Decsion!"
...         elif answer == "Clean Up" or answer == "clean up":
...             print "Wow thats tiring!"
...             print "Lets go to sleep"
...             print "Do you want to sleep more or wake up?"
...             answer = raw_input("Type wake up or sleep and hit 'Enter'.").lower()
...             if answer == "sleep" or answer == "good night":
...                     print "Jeez your super lazy! Good Bye Forever!"
...             elif answer == "wake up" or answer == "wake":
...                     print "YAAWWWNNN"
...                     print "Good You Lived A Long Life!"
...     else:
...         print "You didn't pick bedroom, bathroom or kitchen! Try again."
...         House()
... 
>>> House()
Hello Mister Welcome To Your House 
Do you go to the bedroom or bathroom or kitchen?
Type bedroom or bathroom or kitchen and hit 'Enter'.
You didn't pick bedroom, bathroom or kitchen! Try again.
Hello Mister Welcome To Your House 
Do you go to the bedroom or bathroom or kitchen?
Type bedroom or bathroom or kitchen and hit 'Enter'.
You didn't pick bedroom, bathroom or kitchen! Try again.
Hello Mister Welcome To Your House 
Do you go to the bedroom or bathroom or kitchen?
Type bedroom or bathroom or kitchen and hit 'Enter'.
You didn't pick bedroom, bathroom or kitchen! Try again.
Hello Mister Welcome To Your House 
Do you go to the bedroom or bathroom or kitchen?
Type bedroom or bathroom or kitchen and hit 'Enter'.bath
Oh god the bathroom is dirty!
Do you use it or clean up?
Type use it or clean up and hit 'Enter'.clean
WOW that was tough!
Do you need to go?
Type Yes or No and hit 'Enter'.yes
Number 1 or 2?
Type 1 or 2 and hit 'Enter'.1
PEEEEEEE

Hi there,

As a Mac user, here’s the deal with running python directly out of the terminal… It’s good for a few lines of test code, but I wouldn’t go over 10 lines. It becomes difficult to handle the proper indentation that Python is so strict about, beyond that. My recommendation is to download Python here, which should include the default Python IDE, IDLE. Within IDLE, you have access to both Python console, and a Code Pad to write long programs such as these. While the terminal’s built-in editor is great at times, it’s best sometimes to use what Python recommends.

Best of luck.

What should I use for raw_input answers then?

I use xCode to make my code but I can’t type in the Output

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.