Ex 4.0 - question


As there are no answers in the book to many of the questions. I wanted to ask if my thinking is correct.

It spews out an error because you cannot use a sub-variable to define a primary variable ? Sorry I’m just using my own words and not familiar with the programming lingo.

p/s Since there is no “data” assigned to it per se, so Python doesn’t know what to do with it ? But, it should have derived a value already by working down the lines ?

p/s 2 : Ok I just realized that passengers is missing a “s” …

p/s 3 : Wow, I just realized that the videos are like 10x more instructive than the book itself. What a gem.

Yep, your answer you found later is more correct. Another way to say it is you just made a spelling mistake.

1 Like

I was working on this exercise today, that was the output
in the book is different , I looked for misspelling I could not see it.

Traceback (most recent call last):
File “ex4.py”, line 7, in
carpool_capacity = cars_driven * space_in_a_car
NameError: name ‘space_in_a_car’ is not defined

Hello, stan.
I’m pretty sure your code copied here would help.
It may not be “misspelled”, could be a space or syntax. Error may be on line 6, or 14 ect.

Yep, like @dragonazz says if you paste the code like this:

#  your code here

Or like this:

# your code here

Then we can help. Otherwise, just compare the spelling of your variables and you’ll probably see that you got the name wrong with a small typo.

babies = 200
hospital_beds =150
babies_per_day_born = 15
days_in_a_month = 31

I found all of my misspellings in the exercise above.
I just want to make sure that I understand how variables work.
I can give a number any name that I can associate quick and easy with a certain operation I wanna do
? Just like in math x,y,x work in equation ?

Any name that doesn’t have spaces should work, so just upper case A-Z, lowercase a-z and underscore is the usual.