Solved

Python Error - help please

Posted on 2013-12-02
3
445 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
Turning python script into an applet 12 119
Python 3.5: SQL Results to CSV dump 8 81
wipe a usb using python 5 83
import 13 row from .csv file into another csv file 11 67
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
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 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…
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 …

713 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