Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# Python Error - help please

Posted on 2013-12-02
Medium Priority
460 Views
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
>>>
0
Question by:amigan_99
• 3

LVL 1

Accepted Solution

amigan_99 earned 0 total points
ID: 39691340
I found it..  It's a Python v2 vs v3 problem..

Old: print "The answer is", 2*2

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

LVL 1

Author Comment

ID: 39691344
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

ID: 39691345
It is what it is.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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 lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
###### Suggested Courses
Course of the Month11 days, 22 hours left to enroll