Yesterday, I started learning the course, 100 days of Python. This course starts from the basics and moves to the highest level. Although having a little bit of experience in Python, still I taught taking this to strengthen my knowledge about it. Here I will share my everyday learning with the course. Though I won't take 100 days to complete this course, I will cover each day's lessons in the blogs.
On the very first day, I learned about Printing, Commenting, Debugging, String manipulation, and Variables. All combined at the end of the day we will do a Band name generator program from our learnings.
print(' Hello World!') print(" Hello World!")
Printing a number can be done in two ways: One is using single quotes and the other is using double-quotes. But there can be situations to use both of them. An example of that is below
If a single quote should be used in the print statement, then for printing we should use double quotes and vice-versa.
There is only one way to comment in python by using the '#' symbol. If you want to write any note and it should not be compiled then we use comments.
#The one below this line is a print statement print(" Hii, How are you??")
Debugging is where we find the errors in the code and rectify them.
Suppose if the question is like this and you should debug them. Then,
print(("Have a great day") print("We have won) print("Hello")
All three lines above are having some errors. let's debug them
# 1st line is having an extra open bracket print("Have a great day") #2nd line don't have finishing double quote print("We have won") #3rd line having an extra indentation print("Hello")
Input method :
This is used to take input from the user. Same as the print statement, but the process is terminated only when it gets the required input.
input(" Enter your name :") #After executing print statement it doesn't care about anything and just terminates #But, the input should get the required input for termination.
Generally, variables are used to some value inside them. They can be of int, float, string, etc. In the below example I will show how to store input data
a = input("Enter your name : ") #To print value we should print a print(a)
To concatenate a string with another we use the '+' symbol
print("Hello" + input("Enter your name")) #1st input is compiled and gets input from user #Now name is concatenated with Hello
For finding the length of the string, we use len(variable) function
a = print("Enter your name") b = len(a) print(b)
Here name gets stored into a and length of a is calculated and stored into b and finally b gets printed.
Swapping two numbers
If we have a cup of milk, and a cup of coffee to change milk to coffee cup and coffee to milk cup, we use another cup, and here also the same concept is followed
a = input('entre a value') b = input('entre b value') print(a) print(b) c = a a = b b = c print(a) print(b)
let us assume a as 5, and b as 100. c=a means a value is stored in c then c has 5 and a is empty. a=b means b's value 100 is stored in a and b is empty. b=c means c value 5 is stored in b and c is empty. Now a has 100 and b has 5.
Band name generator program:
a = input("Enter your home town\n") b = input(""Enter your pet name\n") print("Your band name is "+a+" "+b)
Top comments (0)