Solved

Python Error - help please

Posted on 2013-12-02
3
437 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
ID: 39691340
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
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

by:amigan_99
ID: 39691345
It is what it is.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python: sort dictionary of dictionaries 4 113
Python output problem 10 54
python sqlite question 11 46
Live coding in Python 2.13.0 eclipse plugin security 1 43
The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
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 …
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…

813 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

10 Experts available now in Live!

Get 1:1 Help Now