Solved

Python Error - help please

Posted on 2013-12-02
3
427 Views
Last Modified: 2013-12-02
What am I missing??

C:\Python33>python ex4.py
  File "ex4.py", line 10
    print "There are", cars, "cars available."
                    ^
SyntaxError: invalid syntax


The code:

cars = 100
space_in_car = 4.0
drivers = 30
passengers = 90
cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers / cars_driven

print "There are", cars, "cars available."      
print "there are only", drivers, "drivers available."
print "There will be", cars_not_driven, "empty cars today"
print "We can transport", carpool_capacity, "people today."
print "We have", passengers, "to carpool today."
print "We need to put about", average_passengers_per_car, "in each car."


python version info:


C:\Python33>python
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
0
Comment
Question by:amigan_99
  • 3
3 Comments
 
LVL 1

Accepted Solution

by:
amigan_99 earned 0 total points
Comment Utility
I found it..  It's a Python v2 vs v3 problem..

Old: print "The answer is", 2*2
New: print("The answer is", 2*2)

http://docs.python.org/3/whatsnew/3.0.html
0
 
LVL 1

Author Comment

by:amigan_99
Comment Utility
Now it runs correctly:

C:\Python33>python ex4.py
There are 100 cars available.
there are only 30 drivers available.
There will be 70 empty cars today
We can transport 120.0 people today.
We have 90 to carpool today.
We need to put about 3.0 in each car.
0
 
LVL 1

Author Closing Comment

by:amigan_99
Comment Utility
It is what it is.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now