Previously, we learnt that we can add
Firstly, we will greet the user using the print function like explained in py1
Then, we want to ask the name of the user/customer. We can do this with
input function which allows us to take inputs from the user or in this case, our customer. We can use this in many ways and this will get significant later on as well.
To greet and take input from the user we can code something like this:
Now when you run this code you will see that the script doesn’t stop automatically since its waiting for an input. Now once you give an input, you will see that the script doesn’t really do anything.
To store/remember an input, we have to use something known as “variables” in our python programs. Variables is just a way to reuse data in programming, for example, we can do something like
a = 1 and then print the variable named
a anywhere in our code; which would look something like this:
Note you don’t need to add quotation when using print function with variables. This is because its not a string and the data is dynamic, if you put quotes then it would just print “a” everytime.
For out bot we can comment out our input function by adding “#” infront of the line where which would make our script ignore the line thus not running it when the code.
Now you can run the code however nothing will happen.
To add a variable to your input statement, we can just do this:
issue can be called whatever you like. Now you can call it whenever you want in the script, to test this we can just add a print function to print the variable
and this should print whatever is input is given to the input function.
All code used in this course will be availble at: https://github.com/mansoorbarri/python-course/
that’s it <3