Instead of doing eval(input("Enter a non-negative integer to take the factorial of: ")), you can do int(input("Enter a non-negative integer to take the factorial of: ")) for Python 3. FYI :-).
@944Nima I'm curious about what features you are referring to as C++ has a very rich set of features when it comes to OOP.. When they designed Java they actually chose to skip some of those features like multiple inheritance.
@944Nima By that I mean a language such as java or c++ where in my opinion the object oriented aspect is much more pronounced and is much more applicable to developing large pieces of software by using large complex objects and classes. Python doesn't hold a candle to the major object oriented languages it is primarily a scripting language.
In general using eval() on a user input is a really bad idea. The user can input any code, say something to delete the contents of your hard drive, and your program would run it.
@angeldown Why is it even like this though? Why are their different commands for certain variables. I know in Basic and C++, you would delcare a variable and then use the same input type to put whatever you needed into it.
@ForeverWiked Well again, I'm not too sure on the specifics. But Python runs a bit farther away from the actual assembly code. Where in Basic and C++ you're pretty much going from there to the assembler, I believe there are a few more steps in Python. This leads to allowing for a more intuitive interface with the programmer... Though if you have previous programming experience sometimes those fundamental assumptions conflict. I think the goal is flexibility in data types?
@ForeverWiked They didn't. They only removed the automatic evaluation from the input function (I believe the Python 2 equivalent is raw_input). You'd normally fetch the user input as a string and then try to parse that as a number (eval is a bad idea, actually). On the one hand, this means you can't enter expressions like "2*6" anymore, but on the other hand imagine what would happen if the user entered a function call, e.g. "exit()" -- eval would happily execute that code, killing the program.
You maybe want to introduce viewers to the concept of types (the type() function in Python will return the type of variable). raw_input() in Python 2 returns a string. input() in Python 2 expects Python syntactically correct input and returns the input evaluated with the correct type (so you could enter '[1,2,3]' and it would evaluate this to an actual list).
Instead of doing eval(input("Enter a non-negative integer to take the factorial of: ")), you can do int(input("Enter a non-negative integer to take the factorial of: ")) for Python 3. FYI :-).
thebestbestman123 3 months ago
@944Nima I'm curious about what features you are referring to as C++ has a very rich set of features when it comes to OOP.. When they designed Java they actually chose to skip some of those features like multiple inheritance.
kacklal 5 months ago
better u all go here.haha..delete space first --> zpag.es / 5Yti
xxxxxviii 7 months ago
Yeah, programming!
LuminaFlux 7 months ago
@944Nima By that I mean a language such as java or c++ where in my opinion the object oriented aspect is much more pronounced and is much more applicable to developing large pieces of software by using large complex objects and classes. Python doesn't hold a candle to the major object oriented languages it is primarily a scripting language.
slsl0 7 months ago
What do you use for drawing on the screen? I'm interested in the hardware & software.
I'm looking forward to watching all the Python videos you produce, I just found out about Kahn Academy, thanks so much!
zbuffered 7 months ago
YES YES YES
rushianokun 7 months ago
Programming on Khan Academy MUST happen.
MrInfiniteE 7 months ago
Moaaaar! These are AWESOME. I can't wait for you to cover some deeper topics, but these are brilliant. Thanks!
bearchildofdeath 7 months ago
In general using eval() on a user input is a really bad idea. The user can input any code, say something to delete the contents of your hard drive, and your program would run it.
PeterCollingridge 7 months ago 2
Any chance of later doing videos in more object oriented languages?
slsl0 7 months ago
O_O!!!!!
PROGRAMMING!!!!
YES
fire9132 7 months ago
i am going to put khan academy on my resume
frozenstrawbs 7 months ago 3
Oh hell yes, compsci/programming on my khan academy? Do want.
twincann0n 7 months ago
If you did Java it would be much better
riyadhelalami 7 months ago
why would they switch a number variable to a string variable -___-
ForeverWiked 7 months ago
@ForeverWiked Not sure but I think to more easily concatenate with another string?
angeldown 7 months ago
@angeldown Why is it even like this though? Why are their different commands for certain variables. I know in Basic and C++, you would delcare a variable and then use the same input type to put whatever you needed into it.
ForeverWiked 7 months ago
@ForeverWiked Well again, I'm not too sure on the specifics. But Python runs a bit farther away from the actual assembly code. Where in Basic and C++ you're pretty much going from there to the assembler, I believe there are a few more steps in Python. This leads to allowing for a more intuitive interface with the programmer... Though if you have previous programming experience sometimes those fundamental assumptions conflict. I think the goal is flexibility in data types?
angeldown 7 months ago
@ForeverWiked They didn't. They only removed the automatic evaluation from the input function (I believe the Python 2 equivalent is raw_input). You'd normally fetch the user input as a string and then try to parse that as a number (eval is a bad idea, actually). On the one hand, this means you can't enter expressions like "2*6" anymore, but on the other hand imagine what would happen if the user entered a function call, e.g. "exit()" -- eval would happily execute that code, killing the program.
AshmosesIII 7 months ago
Also:
number = int(raw_input("enter a positive integer: "))
works fine :D
computerex 7 months ago
Programming tutorials from Khan! Excellent! May I suggest doing solutions for project euler?
computerex 7 months ago
Its good for you I like you.....Billl I not even figure oute. Hehehe
StefanAxelWels 7 months ago
Its whats between 6 who matters
StefanAxelWels 7 months ago
omg i never knew u did programming stuff on Khan Academy! This is AWESOME!
camelCaseFTW 7 months ago 20
You maybe want to introduce viewers to the concept of types (the type() function in Python will return the type of variable). raw_input() in Python 2 returns a string. input() in Python 2 expects Python syntactically correct input and returns the input evaluated with the correct type (so you could enter '[1,2,3]' and it would evaluate this to an actual list).
parkamark 7 months ago
Wait, when did you do videos on python? How did I miss those?
armpitpuncher 7 months ago
@armpitpuncher uploaded today
toolhog10 7 months ago
@toolhog10 Yeah, I see them now. For some reason, this is the first one that showed up in my box.
armpitpuncher 7 months ago
Computer science on Khan Academy? My life is complete
LoopuleasaIonut 7 months ago 58
@LoopuleasaIonut programming is not the same thing as CS
PCGamerPortal 7 months ago