Indentation in Python- We need to leave spaces after every loops and function declarations. Brackets in Java are replaced by indentation in Python.
If Indentation is not respected, this error is generated.
Moreover, every loop must end by a semicolon ':'
Comments in Python - Comments in Python begin with a '#' These commands are ignored by the interpreter and used to make the program clearer for the developers.
Comments are an essential part of documentation. Proper documentation is a good programming habit. More about it here.
Now, let us see a sample Python program-
print("Program to accept student details.") #here, print() takes one string argument. #input() takes one string argument which it prints out. #input() returns one string argument Rollno=int(input("Enter Roll Number ")) #int() converts the string into an integer type name=input("Please enter a name ") avg=float(input("enter percentage scored ")) #float() converts the string into an float type print("Rollno of the student ",Rollno) print("Name of the student ",name) print("Percentage scored",avg,"%") #here print() takes multiple arguments which it prints in the sequential order
In order to prevent such errors, error handling must be dont, which will be covered in this course...
Here is another program which gives the value of net resistance in parallel
a=int(input("Please enter first resistance ")) b=int(input("Please enter second resistance ")) c=(a*b)/(a+b) #write the brackets carefully print("answer is",c)
1) Write a code in Python to find average of four numbers in one line, without declaring any variables.
2) Write a code to reverse a three digit number in Python.
(Answers can be found here)
To be continued....😏
So friends that's all for this part. 😊 Hope you all are enjoying.😎 Please let me know in the comment section if you liked it or not. 🧐 And don't forget to like the post if you did. 😍 I am open to any suggestions or doubts. 🤠 Just post in the comments below or gmail me. 😉
Thank you for being so patient.👍