Python Tutorial - 2
Hello everyone! Welcome back to another Python tutorial.
What we will be learning:
- Imports: Random, time (basic stuff)
- If, Elif, else statements
- User inputs
Without further ado, let's get started!
Variables overwrite each other. If you create one variable and then change it to another value, the second one overwrites it.
If we run that, it responds with:
This is because, on line 1, you put Albus in the box. And then on line 2, Albus goes out of the box and Severus goes inside. When you print it, it just responds with Severus because that's the most recent one.
So yes, there is a way to put more than 1 thing into the box. So you generate a list.
So printing them out is exactly like a regular variable,
It prints out the whole list, but you might notice that all of it is in square brackets and quotes.
To remove it, you need to convert it.
Now, if you print the new_list out, you will get no brackets.
Now, of course, there is a way to print out a mere part of the list.
The number you put depends. If it is the first item on the list, you put 0. Second gets 1, and so on. You can also use negative numbers, so the last gets -1, second last gets -2, and so on.
1 2 3 4 5 6
-6 -5 -4 -3 -2 -1
Imports, aka modules are special things you can use to do special things. A lot of them are useful, such as time, random, and sys, as I am going to tell you today.
Let's start with time. The most used one of time is sleep.
To first use the module, you must import it.
Once we have it imported, we can now use it.
The time.sleep() will pause the program for a certain amount of seconds. Yes, you can use decimals.
If you run it, you will get
Hello, welcome! followed by a short pause, then
Here are the instructions...
You will be learning about 2 random features today, randint, and choice.
First, import the module:
Randint makes a random number between a range of your choice.
Response will be a random number between 1 and 200.
Choice will pick a random item in a list.
Remember, you need to close both paretheses because we opened 2. Output: random choice.
Loops well, loop the program for a certain amount of time.
Number loops loop it for a specific amount.
the this-can-be_anything will be equal to the amount it has looped. for example, if it repeated for the 2nd time, this_can_be_anything would be equal to 2.
Number will be equal to the next value of the list.
User input allows you to ask a user a question, and then that user will respond.
It will store the user's answer into the variable.
You will enter your name, and it will say
If, elif, else
THis is useful for user input.
If i run the program and enter "sg", I will get
Operators are like equations in Python. You make them, and then they respond with the answer.
It will respond with
Remember when we did lists? Well, we're going to expand that. You can do
But we don't know what "brown" or "black" means.
This prints out the whole thing^^
To print a certain one, do:
This is the end of Python Tutorials. Bye bye!
College students will research with observe gear that adapt to the ONLINE TUITION WEBSITE IN PAKISTAN abilties of a pupil. This means above common students shall be challenged with harder duties and questions when a certain degree is executed. Students who enjoy difficulties with a topic gets the opportunity to exercise greater until they attain the desired degree.
This is a very simple tutorial same as the first lesson. I think it is great for beginners who have never done programming before. Even tho I think it should have other simple stuff rather than imports at the beginning.
The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought you have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention. Fly Safely
I am a student of Information technology and I don't know any of the programming languages. I tried to study but it all went in vain. Then one of my colleagues of Kuwait best CIPD writing help told me about the replit and i started taking your python lessons. they all are amazing, I am now understanding python language and I can now do basic level programming in python too.