1:14:02 if you add a line print(__name__) you will print the current module name, which will be "__main__". That's why you use: if __name__ == "__main__" which means: "if the module name where I am right now is "__main__", then and only then run the code below." The code below will usually call your main function, which, in turn, will call any other function you put in it. All other modules you import will be not "__main__" when the main module is your current file. Therefore, if they also have this statement (if __name__ == "__main__"), their functions will not run automatically when you import them, because this statement will be false. Please note that UA-cam is removing some of the underscores in my comment.
I'm just grateful for this incredible amazing course from this legend man and the CS50 team. I've never wished a lecture in a course to not end but I do when I watch your courses. thank you!
I remember reading/watching something ages ago where David explained that he developed his teaching skills by watching other teachers do things well and badly, analysing exactly what do to and avoid, and - ta da! - that’s why he’s so good 😊
for the past couple of weeks, I was trying to remember the band Weezer and their songs, but I just couldn't. who knew I would find them again in a CS50 lecture. crazy how life works
out of all the possible lectures i happen to end up with this one somehow, well it was the pressure of ''tutorial hell'' phase that landed me here and now i only feel confortable to watch this one with puppets and learn. what a weird world we live in. I am so happy to reach so far. i cant balieve i came this far, i knew nothing from looking at any code and now i know so much from 3 weeks back to now. I feel like the last half of this cource gonna be very hard. hope now. so far its been going smooth, well if i look back not that smooth, i had my ups and downs, crying and forcing myself to continue. I never enjoyed studying like this before in my life.
In 33:23, David says that it is better to keep all of your error handling separate from the code you really care about. But I think that checking first if there is an error could execute more lines of code unnecessarily. You expect that most of the time the code will not have an error, so it might be better to check if we can proceed without errors first, and then verify which error we have.
I think what he is trying to say is, all current US coins have a head of a famous US person on one side, while, a euro may not have a picture of a person's head on a side of the coin. Historically, "heads" referred to the image of the king or queen on one side of the coin.
Often more convenient (i.e., faster) to provide input to programs via the command line, rather than wait to be prompted to provide one value at a time!
17:01 why i got this error when i typed exactly the same codes? AttributeError: partially initialized module 'statistics' has no attribute 'mean' (most likely due to a circular import)
had same issue. It was because I named the file 'statistics.py'. I changed the name and it worked. You may have the same clash in your working directory.
21:20; This would be a scenario that would benefit by importing with from, as like:"from sys import argv"(?). Because sys - is my answer. 43:58; I actually invited someone whose name is argv - what do i do now? Help!(!).
As a learner who is still in the early stages, I tried to mess around with random. I named the file random.py since I was going to be testing the use of random. Everything single thing I tried kept giving me the same error. I copy pasted examples from different sites and nothing worked. Turns out it's because I named the program random.py. I changed the name and everything worked flawlessly. It might be obvious to some but it's not been mentioned in any video I've seen
Came up with the same problem... if you're using a module (in your example random) and your file is also named `random.py`, turns out Python tries to access your file random.py itself instead of the module, and it is called a "Circular Import" ! Renaming our file is indeed the way, thanks for mentioning it !
so you want to use an exception when you can anticipate that python could possibly crash. And when I say crash, I simply mean, not run. Meaning any case where python will throw some error of any kind. I know you have seen this before, like what happens when you try to run print("hello world" and forget to close the parenthesis. Python will crash and it will complain by showing you a kind of confusing looking message. SO, another more relevant example where you can anticipate python might crash is when you are passing a user input into the int() function. I love actually testing how functions will act myself by always having a python shell open where I can just run one line commands. Or if you are new to the idea of a shell, you can just have a separate python file open where you are just testing simple one liners like what python does when you run int(5) or int("5") or int("hello"). if you were to test those out, you would see that int(5) doesn't throw an error of course, and int("5") also doesn't throw an error even though "5" is a string. But int("5.5") actually throws an error! and more importantly for my discussion here, int("hello") throws an error. Meaning your program will actually crash if you ever pass letters into the int function. Crashing is no good. There is no conditional whether it be if, else, or elif that will prevent a crash. Won't matter what conditionals you got if your program crashes. So what you need in this case is a try and except. you would try running userInput = int(input("Please input some stuff")) , realizing that you are in danger of your programming crashing if the user puts in letters so if the user puts in an integer, your code will go to the try block. if the user inputs numbers but saved as a string, you are still good it will go to the try block, but if the user inputs letters, now it will send you to the except block and execute whatever code is there in the except block. IT DOES THIS INSTEAD OF CRASHING.
I think we can just write " from random import* " or " from sys import* " without adding choice or any other function and then if we want to use functions like choice or argv we have just to write choice() or argv() etc.... Am I right?.
43:01 if sys.argv[1:3] prints sys.argv[1] followed by sys.argv[2] why doesn't sys.argv[1:-1] print sys.argv[1] followed by sys.argv[0] which would output "hello, my name is David" followed by "hello, my name is name.py". that makes slices behave consistently so that the colon always means print FROM the value to the left of the colon(inclusive) TO the value to the right of the colon(non-inclusive)
Slicing in python actually takes 3 arugments: [start index : end index : step]. A negative number would mean reversing the direction and counting from the right of the list. For end index, -1 in [1:-1] means that the program stops at 1 element before the end of the list. This is useful because we may not always know the length of the list, and thereby the exact index of the last item. This syntax allows us to exclude the first and last element and get all the values in between, without knowing how many item is in the middle. Furthermore, step by default = 1, which means the program would increment through every element in the list. Overriding the step can make us jump through some elements of the list. e.g. [1, 2, 3, 4, 5][::2] -> [1, 3, 5] If the step takes a negative number, the direction of incrementing would be reversed. e.g. [1, 2, 3, 4, 5][::-1] -> [5, 4, 3, 2, 1]
why dont i get terminal with doller sign or the one like David uses. How can i fix this . i am using vs code and i cant use sys.argv properly due to this
While I value the practical nod to Weezer (or Rage Against The Machine - Tom Morello), it's crucial to acknowledge that the foundation for cybersecurity tools such as Cloudflare Turnstill begins from ua-cam.com/video/MztLZWibctI/v-deo.html onwards.
Has someone completed this course in like a week or so? Coz I'm 4 days into this course and I'm already on this lecture. Also, does this course get increasingly difficult after this week?
@@intxcatedfinishing lectures isn't that hard😂.... 4 days 4 lecture??? Did even practice a little😂... There is no use of lectures its just to guide you ...focus more on problem sets by cs50 and other resources
Wow, you are sooo much smarter than everyone else! Did you also complete all 4 problem sets that have 21 exercises in 4 days? I won't wait for your answer.
I'm five days into the course and completed all the problem sets so far. Have spent around two to four hours a day solving the problems. So it's definitely possible to get this far in four days. I have some prior experience in Python tho.
Regarding APis: how do we find APIs, be it for gmails or UA-cam or any other site and how would you go about a problem with sites that require passwords and usernames
Hello Sir with all your respect I want to tell you ,This leacture is quite hard and most of the concepts are not clear..I think the main reason is visual code, because my visual code window is not appear similar as you show on your video leacture.If possible kindly upload a detail video related to visual code step by step.
Read the documentation for each of the packages/libraries/ modules and the functions used in the program then you will understand. Without reading the documentation it’s hard to understand what’s going on
cowsay library is giving me troubles. I did install it. but it is not giving me the functions. for example "cowsay.cow("string) is giving me error. AttributeError: partially initialized module 'cowsay' has no attribute 'cow' (most likely due to a circular import) what is happening here exactly???
A bit late, but I came up with the same problem... if you're using a module (in your example cowsay) and your file is also named `cowsay.py`, turns out Python tries to access your file cowsay.py itself instead of the cowsay module, and it is called a "Circular Import" ! Renaming your file is the way, hope it helps :)
@@sparkz1330 though, it's worth noting that sys.argv is not a function in the sys library, it's technically a variable. So in this example, len(sys.argv), you're using a function: #len() and passing it a variable as an argument: #sys.argv
@@sparkz1330 also, in the example: num1 =int(input("enter a number")) You can technically pass the input() function as an argument to the int() function, because the int() function can take strings as an argument, as long as it's a string of integers (eg. "123"), and the input() function returns a string. If you the input() function returned words (eg."cat"), it will cause a runtime error, as you cannot convert "cat" into a string.
To answer your question though. If you want to pass one function to another as an argument, take into consideration the parameters of the function you're passing the argument to (what data type does the function take as an argument? A string? An int? A list?), you also need to take into consideration what data type does the function you're passing as an argument return (does it return a string? An int? A list?). Just make sure that the return data of the one function matches the data type of the parameters of the other function, then yes, you can pass a function as an argument in another function.
hello,for the cowsay part i did everything as you told, in pycharm and it tells me "No such file or directory ". I am quite sure it is the exact same file I'm using. I also tried it on VSC it also gave me the same warning? can anyone possibly help me? my file's name is say.py just like sir david's. i type the python say.py name on the terminal. i have the packages downloaded as well
verified certificate might be accepted as credit in some degree programs, or some employers may be willing to to use the edx course in a professional development program. Generally speaking, certificates are good to have, but prospective employers probably aren't going to care about whether or not CS50 Python certificate is the free version or verified (paid) version. At a certain point, you'll want to have open source projects to demonstrate your ability. The same is true about college degrees as well-- College degrees are good to have but what is more important is having done things with the certificate/degree to demonstrate your proficiency.
1:07:21 if we treat whatever stored in variable "o" as a python code and follow along the loop, the "result" variable at line 12 returns as the list that stores the dictionary that holds the key "trackName" so essentialy we are accesing the value paired with the key "trackName" from a list called "result". but since the code worked anyways i'm guessing iterating a json data isn't as same as iterating python data or i'm making a mistake please drop a reply if you think you know what's going on
If --name-- == "--main--" Means if the the name of this file which is sayings.py have the main function excute main in this file only. And in this way say.py which we import the function hello from , will not excute main but only hello ...
In this scenario, If we know for a fact that probability of entering the name correctly is high, then is it a good design to have this condition tested first in the if loop? If len(sys.argv) == 2: print("hello, my name is", sys.argv [1]) Code: 1 import sys 2 3 if len(sys.argv) < 2: 4 ... print ("Too few arguments") 5 elif len(sys.argv) > 2: 6 •• print ("Too many arguments") 7 else: 8 ... print("hello, my name is", sys.argv [1])
It will probably come down to preference, as it would technically be the same code, but just the conditions and the else block changes. If you start with "if len(sys.argv)==2:", you will then have to add an elif to test one of the conditions (eg. "if len(sys.argv) > 2:"). Since you've tested bigger than and equals to, you can use the else statement as there's only one other option (smaller than). Again, in essence, this is pretty much the same code as the one in the video. It's probably only "better" if you have a preference for testing the == condition first, but it doesn't really improve the code in any way.
The puppets talking to each other before class starts 😂😂😂
1:14:02
if you add a line
print(__name__)
you will print the current module name, which will be "__main__".
That's why you use:
if __name__ == "__main__"
which means:
"if the module name where I am right now is "__main__", then and only then run the code below."
The code below will usually call your main function, which, in turn, will call any other function you put in it.
All other modules you import will be not "__main__" when the main module is your current file. Therefore, if they also have this statement (if __name__ == "__main__"), their functions will not run automatically when you import them, because this statement will be false.
Please note that UA-cam is removing some of the underscores in my comment.
omg thanks so much. you read my mind i was so confused
Thanks for clarifying.
Thank you
that was a huge "Gotcha", thank you
and i u try to print the __name__ in a file where its using that custom library, it will not print __main__ but the name of the file
Just want to say how much I am enjoying this course so far. Thanks to David and the CS50P team
I'm just grateful for this incredible amazing course from this legend man and the CS50 team. I've never wished a lecture in a course to not end but I do when I watch your courses. thank you!
hmhm btw did your requests module works? i keep on getting attribute error while using cs50dev while implementing this course
can't wait for the exercise to be 100x harder than this lecture.
Fr fr
cs50x was way worse so far
1000
@@cagedblue85 it's not that hard guys just some libraries and stuff
That is how learning works. If you were provided all the answers in-context you wouldn't be learning. You'd be repeating.
My God, his teaching skills are insane. His communication skill, flow and organization of thoughts. Damn, could I ever get there...
I remember reading/watching something ages ago where David explained that he developed his teaching skills by watching other teachers do things well and badly, analysing exactly what do to and avoid, and - ta da! - that’s why he’s so good 😊
@@alwaysleaping Ohh, that's such a nice thing to know. Honestly, I would probably have imagined it as an innate thing he was born with
Great Work Sir. CS50 has done a great social work for the people eager to learn coding.Thanks again
7:37 prog1 10:34 prog2 13:15 prog3 15:23 prog4 19:30 prog5 24:50 prog6 28:38 prog7 30:49 prog8 42:43 prog9 1:02:09 prog10 1:05:49 prog11 1:08:04 prog12 1:12:44 prog13 1:13:56 prog14 1:15:22 prog15
This is a priceless opportunity to have access to lessons like this. Thank you so much.
one of the best lessons between cs50x and python
for the past couple of weeks, I was trying to remember the band Weezer and their songs, but I just couldn't. who knew I would find them again in a CS50 lecture. crazy how life works
out of all the possible lectures i happen to end up with this one somehow, well it was the pressure of ''tutorial hell'' phase that landed me here and now i only feel confortable to watch this one with puppets and learn. what a weird world we live in.
I am so happy to reach so far. i cant balieve i came this far, i knew nothing from looking at any code and now i know so much from 3 weeks back to now. I feel like the last half of this cource gonna be very hard. hope now. so far its been going smooth, well if i look back not that smooth, i had my ups and downs, crying and forcing myself to continue. I never enjoyed studying like this before in my life.
Seems like you learnt the art of wanting to study more and more kudos to you,
how far have you reached today after 8 weeks of this comment?
Thank you for the fantastic session, David! You're the best!
Great presenter! Very well organized! Thanks for publishing this!
API's section I love the most
God Bless you David Malan
As usual good lesson and extremely difficult.
I got no words to describe my appreciation but turned out only able to say David Malan is Awesome.
Salute you, David. That's awesome, you are a great educator!
Hello
HELLO
@@MadhavSharma-lu5ez
HELLO@@TheEagle-lp2mh
Thanks again for these epic videos with king David Malan!
Dude this lecture is absolutely insaneeee
Awesome musical podcast👌 shilpa mam ke behtareen gaano ko sunkar maza a gaya ❤ amazing shandar 🙏
❤am riding this to the end, thanks a lot prof
1:06:13 knowing how to manipulate/read data from these structures are so important
In 33:23, David says that it is better to keep all of your error handling separate from the code you really care about. But I think that checking first if there is an error could execute more lines of code unnecessarily. You expect that most of the time the code will not have an error, so it might be better to check if we can proceed without errors first, and then verify which error we have.
Taking and watching CS50 is really like enjoying favourite movie😎
Imagine if humans watched stuff as informative as this instead of stupid Netflix movies. We'd be living 1000 years into the future.
@@1tubax 😄😄1000%True
@@1tubaxthat starts at home once we mandate informative content for our youngins
@@1tubax look at it this way, Netflix itself is a result of implementation of these technologies, "stupid" is relative.
@@chikomedia strong men (inventors) create easy times (Netflix) which create weak men
4:17 "A coin that in the US has heads or tails" I'm not from the US but I've never seen a coin with three sides David.
I think what he is trying to say is, all current US coins have a head of a famous US person on one side, while, a euro may not have a picture of a person's head on a side of the coin. Historically, "heads" referred to the image of the king or queen on one side of the coin.
Great question at the @50:00 minute mark.
This guy always ask such great questions
Дуже добре. Мені сподобалося як Ви викладаєте матеріал
Good closing 👍, "goodbye, world"
00:19:13 - Command-line Arguments, sys
Thank you for making this video!
My first watch through of this one - question - why would you use argv() instead of an input statement? What is gained here? Thanks
Often more convenient (i.e., faster) to provide input to programs via the command line, rather than wait to be prompted to provide one value at a time!
@@davidjmalan Thank you David, I'm sure it will become apparent once I use it more. This class is awesome
58:19 Didnt know David was chill like that 🥶
19:00
12/15/23
33:00
Slice
17:01
why i got this error when i typed exactly the same codes?
AttributeError: partially initialized module 'statistics' has no attribute 'mean' (most likely due to a circular import)
I think your python doesn't have pre-installed statistics library
pip install statistics in terminal window
had same issue. It was because I named the file 'statistics.py'. I changed the name and it worked. You may have the same clash in your working directory.
@@Don_Modern_Ancestor yes it was the problem that i realized already, thanks anyway
@@sedo7 I figured you had, but I posted there if others come across the same issue.
21:20; This would be a scenario that would benefit by importing with from, as like:"from sys import argv"(?). Because sys - is my answer. 43:58; I actually invited someone whose name is argv - what do i do now? Help!(!).
As a learner who is still in the early stages, I tried to mess around with random. I named the file random.py since I was going to be testing the use of random. Everything single thing I tried kept giving me the same error. I copy pasted examples from different sites and nothing worked. Turns out it's because I named the program random.py. I changed the name and everything worked flawlessly.
It might be obvious to some but it's not been mentioned in any video I've seen
Came up with the same problem... if you're using a module (in your example random) and your file is also named `random.py`, turns out Python tries to access your file random.py itself instead of the module, and it is called a "Circular Import" ! Renaming our file is indeed the way, thanks for mentioning it !
I did the same thing haha. Had no idea what was wrong so I asked chatgpt. It gave me the answer.
How do I know, or how can I decide when to use exceptions and when to use conditionals?
so you want to use an exception when you can anticipate that python could possibly crash. And when I say crash, I simply mean, not run. Meaning any case where python will throw some error of any kind. I know you have seen this before, like what happens when you try to run print("hello world" and forget to close the parenthesis. Python will crash and it will complain by showing you a kind of confusing looking message. SO, another more relevant example where you can anticipate python might crash is when you are passing a user input into the int() function. I love actually testing how functions will act myself by always having a python shell open where I can just run one line commands. Or if you are new to the idea of a shell, you can just have a separate python file open where you are just testing simple one liners like what python does when you run int(5) or int("5") or int("hello"). if you were to test those out, you would see that int(5) doesn't throw an error of course, and int("5") also doesn't throw an error even though "5" is a string. But int("5.5") actually throws an error! and more importantly for my discussion here, int("hello") throws an error. Meaning your program will actually crash if you ever pass letters into the int function. Crashing is no good. There is no conditional whether it be if, else, or elif that will prevent a crash. Won't matter what conditionals you got if your program crashes. So what you need in this case is a try and except. you would try running userInput = int(input("Please input some stuff")) , realizing that you are in danger of your programming crashing if the user puts in letters so if the user puts in an integer, your code will go to the try block. if the user inputs numbers but saved as a string, you are still good it will go to the try block, but if the user inputs letters, now it will send you to the except block and execute whatever code is there in the except block. IT DOES THIS INSTEAD OF CRASHING.
@@danielgray8053 Thanks :)
@@marticus9170 how's it going with the assignments , which one are you on?
I think we can just write " from random import* " or " from sys import* " without adding choice or any other function and then if we want to use functions like choice or argv we have just to write choice() or argv() etc.... Am I right?.
!You're right
Perfect as always
Incredible....EXCITING!!!!
43:01 if sys.argv[1:3] prints sys.argv[1] followed by sys.argv[2] why doesn't sys.argv[1:-1] print sys.argv[1] followed by sys.argv[0] which would output "hello, my name is David" followed by "hello, my name is name.py". that makes slices behave consistently so that the colon always means print FROM the value to the left of the colon(inclusive) TO the value to the right of the colon(non-inclusive)
Slicing in python actually takes 3 arugments: [start index : end index : step].
A negative number would mean reversing the direction and counting from the right of the list.
For end index, -1 in [1:-1] means that the program stops at 1 element before the end of the list. This is useful because we may not always know the length of the list, and thereby the exact index of the last item. This syntax allows us to exclude the first and last element and get all the values in between, without knowing how many item is in the middle.
Furthermore, step by default = 1, which means the program would increment through every element in the list. Overriding the step can make us jump through some elements of the list.
e.g. [1, 2, 3, 4, 5][::2] -> [1, 3, 5]
If the step takes a negative number, the direction of incrementing would be reversed.
e.g. [1, 2, 3, 4, 5][::-1] -> [5, 4, 3, 2, 1]
I'm writing the exact same code of sys module at 23:42, but it's not working for me. Can anyone point out that what could be the possible reason?
why dont i get terminal with doller sign or the one like David uses. How can i fix this . i am using vs code and i cant use sys.argv properly due to this
Awesome lecture!
While I value the practical nod to Weezer (or Rage Against The Machine - Tom Morello), it's crucial to acknowledge that the foundation for cybersecurity tools such as Cloudflare Turnstill begins from ua-cam.com/video/MztLZWibctI/v-deo.html onwards.
I m using pycharm IDE. But ı can't write anyting in console. Previously I just click on run button but know things are changed . Pls help me !!!!
Has someone completed this course in like a week or so? Coz I'm 4 days into this course and I'm already on this lecture.
Also, does this course get increasingly difficult after this week?
how did it go?
@@intxcatedfinishing lectures isn't that hard😂.... 4 days 4 lecture??? Did even practice a little😂... There is no use of lectures its just to guide you ...focus more on problem sets by cs50 and other resources
Wow, you are sooo much smarter than everyone else! Did you also complete all 4 problem sets that have 21 exercises in 4 days? I won't wait for your answer.
I'm five days into the course and completed all the problem sets so far. Have spent around two to four hours a day solving the problems. So it's definitely possible to get this far in four days. I have some prior experience in Python tho.
Thanks! Brilliant
Regarding APis: how do we find APIs, be it for gmails or UA-cam or any other site and how would you go about a problem with sites that require passwords and usernames
best use of "good bye"
Guys! Do I need to learn all of the methods in the random module?
the moduie cowsay doesn't work on my computer...
AttributeError: module 'cowsay' has no attribute 'cow'
محمد عمر الي مشرفنا ورافع رسنا
Whenever I use pip to install a package, once I run the program I get a reportMissingModuleSource Error how should I solve the problem
They are many different CS50 which one did you do? Thx
I have one regarding the use of Api . If we enter the value of limit that not exist what happen in that situation?
Hello Sir with all your respect
I want to tell you ,This leacture is quite hard and most of the concepts are not clear..I think the main reason is visual code, because my visual code window is not appear similar as you show on your video leacture.If possible kindly upload a detail video related to visual code step by step.
Best to use code.cs50.io !
Read the documentation for each of the packages/libraries/ modules and the functions used in the program then you will understand. Without reading the documentation it’s hard to understand what’s going on
for i in range(1000000000000000)
print("THANK YOU SO MUCH!")
why is my terminal not working the same way?
Can we take the exam per coarse? Like, here . erm ... or nevermind.
cowsay library is giving me troubles.
I did install it. but it is not giving me the functions.
for example "cowsay.cow("string) is giving me error.
AttributeError: partially initialized module 'cowsay' has no attribute 'cow' (most likely due to a circular import)
what is happening here exactly???
library not installed i guess
A bit late, but I came up with the same problem... if you're using a module (in your example cowsay) and your file is also named `cowsay.py`, turns out Python tries to access your file cowsay.py itself instead of the cowsay module, and it is called a "Circular Import" ! Renaming your file is the way, hope it helps :)
My sys.argv is not executing properly. When I am providing index its showing some error. Please help
Not index error
But you didn't show the code nor the error name
@@sayori3939 I actually solved it I just needed to change my compiler path.
But thanks for concern
@@prathamsolanki742 '0' hehe i remember there were ine time i messed mingw path and i had to reinstall vs code ._.
@@prathamsolanki742 how did you changed the compiler path
if len(sys.argv)
great sir love you
i dont know what the f is happening with vs code i m not able to use any of the interface codes.
Thanks David
Thank you so much!
This is helpful ❤
Are there problem sets or just the regular cs50x?
See cs50.harvard.edu/python/2022/psets/!
there r
Start again Thanks.
Where do I report a problem with check and submit?
How can we use len function on a function , #len(sys.argv)>2
can we use function in the len function's argument
yes like when you use int() and input like num1=int(input("enter an number"))
@@aymenslim9900 Thanks a lot , it helped me
@@sparkz1330 though, it's worth noting that sys.argv is not a function in the sys library, it's technically a variable.
So in this example, len(sys.argv), you're using a function:
#len()
and passing it a variable as an argument:
#sys.argv
@@sparkz1330 also, in the example:
num1 =int(input("enter a number"))
You can technically pass the input() function as an argument to the int() function, because the int() function can take strings as an argument, as long as it's a string of integers (eg. "123"), and the input() function returns a string. If you the input() function returned words (eg."cat"), it will cause a runtime error, as you cannot convert "cat" into a string.
To answer your question though.
If you want to pass one function to another as an argument, take into consideration the parameters of the function you're passing the argument to (what data type does the function take as an argument? A string? An int? A list?), you also need to take into consideration what data type does the function you're passing as an argument return (does it return a string? An int? A list?).
Just make sure that the return data of the one function matches the data type of the parameters of the other function, then yes, you can pass a function as an argument in another function.
i watched 3 lesson in 1 days fun learning. like cowsay haha and new memory brain know about __name__ == "__main__" use for . Thanks Ph.D david
hello,for the cowsay part i did everything as you told, in pycharm and it tells me "No such file or directory ". I am quite sure it is the exact same file I'm using. I also tried it on VSC it also gave me the same warning? can anyone possibly help me? my file's name is say.py just like sir david's. i type the python say.py name on the terminal. i have the packages downloaded as well
Did u use pip to install the package?
Happy rakhsha bandhan form india
all countries united here
Can someone correct my code please:
import sys
Print("Hi I'm", sys.argv[1])
Print has a capital P, although maybe that's just an error within the UA-cam comment. Otherwise, looks fine
@@naomiparsons462 in my code the 'p'
Was'nt capital 🫤
dont use '
Does someone have a verified certificate of this course? Do you feel any actual benefit of that?
verified certificate might be accepted as credit in some degree programs, or some employers may be willing to to use the edx course in a professional development program. Generally speaking, certificates are good to have, but prospective employers probably aren't going to care about whether or not CS50 Python certificate is the free version or verified (paid) version. At a certain point, you'll want to have open source projects to demonstrate your ability. The same is true about college degrees as well-- College degrees are good to have but what is more important is having done things with the certificate/degree to demonstrate your proficiency.
1:07:21 if we treat whatever stored in variable "o" as a python code and follow along the loop, the "result" variable at line 12 returns as the list that stores the dictionary that holds the key "trackName" so essentialy we are accesing the value paired with the key "trackName" from a list called "result". but since the code worked anyways i'm guessing iterating a json data isn't as same as iterating python data or i'm making a mistake please drop a reply if you think you know what's going on
Thanks ❤
57:00
15:48
50:00
53:28
58:10
54:01
Prof Malan likes Weezer. What a chad
i didnt understand last one
If --name-- == "--main--"
Means if the the name of this file which is sayings.py have the main function excute main in this file only.
And in this way say.py which we import the function hello from , will not excute main but only hello ...
@@relaxer7329 thanks
if __name__ == main
He actually installed cowsay....
Imagine if you go to the restroom and when yiu come back you see this 50:00
everyone did xD
@@amitKumar-xn1bt i actually thought about installing it :3 but sadly I'm too deep into my havk code to do it ._.
@@sayori3939 havk code ? :D
1:8:38 HAHAHAH yaani
Hernandez Sandra Lee Thomas Anderson Matthew
Pers
32
In this scenario,
If we know for a fact that probability of entering the name correctly is high, then is it a good design to have this condition tested first in the if loop?
If len(sys.argv) == 2:
print("hello, my name is", sys.argv [1])
Code:
1 import sys
2
3 if len(sys.argv) < 2:
4 ... print ("Too few arguments")
5 elif len(sys.argv) > 2:
6 •• print ("Too many arguments")
7 else:
8 ... print("hello, my name is", sys.argv [1])
It will probably come down to preference, as it would technically be the same code, but just the conditions and the else block changes.
If you start with "if len(sys.argv)==2:", you will then have to add an elif to test one of the conditions (eg. "if len(sys.argv) > 2:"). Since you've tested bigger than and equals to, you can use the else statement as there's only one other option (smaller than).
Again, in essence, this is pretty much the same code as the one in the video. It's probably only "better" if you have a preference for testing the == condition first, but it doesn't really improve the code in any way.
@@winstonbarendse3647 thanks a lot for explaining. Cheers.
sratrt at: 39:06