Gettin' User Input and Comments
Comments are really useful and user input is useful for calculators
Homework Answers from last time (ignore if you didn't read last lesson)

Tbh , you can do it a lot of ways , you don't have to have as many lines , but I did it , because this is supposed to be a beginner frendly tutorial.
Here's a way to make the function 2 lines without lambda :

Gettin' User Input
What it is, why would I use it?
User Input is one of the ways a program can be interactive by requesting bits of data from users in the form of numbers/strings/etc . User Input can be really useful when making calculators , when making huge scripts and you wanna run only a part , or switching mode of a script or just giving it the full path to a file.
How to implement it?
Well the command is pretty easy input(<text displayed that asks for a thing>) .

Here's a program that will ask for your credit card number , of course this is fake ,because you also need expiration date and the pin unfortunatly. Anyways jokes aside , when you run this , the program will display the message in console and you will write just after it:

As you can see the user will have to type where my 'typing cursor' was , what happens if you write anything? Well if you press enter it will close the program , that's for sure , since that's the only line and it stops the program to do anything till you type something there or just press Enter.
Where Does the Input Get Saved?
Well , it doesn't , to get it saved you have to do something like variable = input("message : ")
Now that it's saved like a variable , you can do a lotta stuff with it like passing it in a function or in some loops
Comments, the most useful part of writting a script
What it is , why SO USEFUL?
Imagine that you joined discord for help and you have a problem with your script , a messed up function and someone there sends you a new example of function . In case his function won't work you are gonna probably either make a clone file with only function changed or just save your 'not working function ' in a .txt or anywhere else. Well you don't have it to save anywhere outside the script since you can use THE POWE' OF comments.
Also let's say your script is gonna be used by a lot of people and you don't have time for them to ask that many questions , so you include comments to tell people what the script does or what parts of it do. Also comments can help even you in case you forgot that the script even existed so you forgot what it does.
Are you gonna tell me how to use it?
This ain't a question for you , it's a question you probably gonna ask and you already know the answer.
It's really easy : just write # before the code you want it to be 'commented out' and when you run the script it won't run . Example :

As you can see , the commented text gets grayed out and won't run by program , in this case saving our drive from formating . Of course the function above didn't do anything and if you don't believe me that comments make pieces of code not run , replace the name of the function that's commented with input('message') and you will see that it won't stop the program to ask for input.
Is there a magical way to comment out a LOT of lines at once?
Yeah , you guessed it perfectly right , to comment any number of lines just write '''[aka triple quotes] at the start of what you wanna comment and again'''where you want it to stop. Example :

Let's say that we just want the script to run 'Do you like turtles?' instead of all the script above , but you don't wanna rewrite them if you wanna run them. You will have to do something like that
Practice REALLY Makes Perfect , Believe Me!
For your homework today , I want you to remind yourself of the knowledge learnt at the 'Function Parameters' lesson and combine that with the today lesson. Your task is to make a function that will print out whatever you input in , and the thing you will have to input will be user input . Also something optional : try to do it again , without a function , and only in a single line
We'll talk about the answers at the start of the next lesson
Keep up the good work
Last updated
Was this helpful?