Writing a Simple Factorial Program. (Python 2)

preview_player
Показать описание
Writing a simple factorial program with a "for" loop
Рекомендации по теме
Комментарии
Автор

Omg I never knew Sal Khan taught this. The guy literally knows everything ....

timmytim
Автор

Simply the best! My dream is to say you "Thank you " personally !

DHDemid
Автор

@vibol03 Google uses it for a lot of their development (I believe it is their language of choice). Khan Academy's server side code is all Python.

khanacademy
Автор

This makes me infinitely happy Sal is posting computer science videos. To those wanting other languages, they'll probably come later. Python is an excellent starting language.

MemoryDealer
Автор

number= int(input("Enter the number= " ))
product=1
for i in range(number):
product= product*(i+1)

print("Factorial of Number is :", product)

gorkimcgregor
Автор

legendary, thanks Sal, im a python hacker myself and its good to see you popularizing a great language. I have also gone through alot of your mathematics videos and finance videos and man, i hope KA runs for a very long time !

dellbucket
Автор

This works sir. I was stuck on this. Thank you so much!

murtazaakbarreborn
Автор

That fucking awesome feeling you get when something works.
Thanks Sal!

hedonism
Автор

@ImUncreative100 These are the fundamental skills that every computer programmer MUST know and be familiar with. No, you probably won't use these exact programs in your day-to-day life, but you need to familiar with For Loops and passing arguments in order to build even basic programs. Sal is just laying down the basics of the language. Once you get the basics down, you can begin practicing with larger projects.

FireheadLazzo
Автор

you can simple this:
import math

n = int(input("enter the number: "))
result = math.factorial (n)
print(result)

inbanpythonic
Автор

I hate that everyone in the comments is complaining. Are you serious? You should be glad he is teaching programming at all. Maybe in the future he will do a C++ playlist, for now this should be suffice for all of you.

Redexn
Автор

Thank you for your video, if I may have a short question. How does your program work in general, given that the input returns a string, and how do you not get an error in the program when you did not convert the input string to an integer?? Thanks in advance for your reply

mikijasar
Автор

Can't wait to see more programming vids. Thanks, Sal!

brHOLLAND
Автор

"Why isn't the translation feature enabled for some passages, including this one?"

Fatima-xbmp
Автор

would it be slightly faster if you made it 'for i in range (1, number + 1)' and not add 1 to i in the loop?

mickstarify
Автор

Very cool! A Computer Science set of videos sounds awesome.

dneelyep
Автор

I modified mine a little...to include the index values:

def factorial (number):

if number <=1:
return 1
product = 1
for i in range (number):
product = product * (i+1)
print(i, product)
return

ThinkandCreate
Автор

If I ever have a chance of learning how to program, it'll be from Sal.

henik
Автор

Would adding the eval around input be backwards and forwards compatible with both python 2 and 3? It would just be redundant on 2 right?

Omlet
Автор

it works, but I wouldn't say it's easier. You are passing the "number" variable to the range() function and at the same time change "number" inside the loop. It works and it's okay, if you know that python passes the "number" variable to a local variable inside of range(), but for someone less experienced it might be hard to make out, what's actually going to happen, since changing the variables, that are used inside of the loop header, is generally a nasty thing. So no: not recommended.

SaniSensei