DEV Community

Cover image for Restart Python class2
Guna Ramesh
Guna Ramesh

Posted on

Restart Python class2

What is predefined?
The Word has meaning by python before users used it.
example:

>>> print("Gunalan")
Gunalan
>>> len("karthi")
6
>>> 

Enter fullscreen mode Exit fullscreen mode

len is also a predefined function in Python, and it is used to find the length of a sequence.
print is also a predefined function in Python, and it is used to print the sequence.

If you want to see how many keywords in python,go to terminal then call python.
After calling you did like this:

>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

Enter fullscreen mode Exit fullscreen mode

in this words you cant used a variable name and some places.

*I got some Golden Rules of Programming!
*

1.Never Say "I don't know",say " I will try".
defination:You can go to the interview,interviewer ask a question about anything in programming or that job.If you say "I don't know" that is made bad impression of yourself to interviewer.So say i will try its pushing yourself to next step.
2.Known to Unknown
What is Known to Unknown?
ex:
expected output is :
1
2
3
4
5
you did try to own idea if its simple!

a=1
while a<=5:
  print(a)
  a=a+1

Enter fullscreen mode Exit fullscreen mode

if you dont no loop ,but you know what is print function doing

print("1")
print("2")
print("3")
print("4")
print("5")

Enter fullscreen mode Exit fullscreen mode

They ask ans only not how you did.Now the first rule also solved.
3.Don't think about entire output.
If you think the entire output in above you cant done.

print("1")

Enter fullscreen mode Exit fullscreen mode

you know about how to print 1 then you following the rules and print other numbers.

print("2")
print("3")
print("4")
print("5")
Enter fullscreen mode Exit fullscreen mode

4.Think about next step only.
Simple Example:
Get the number from user then find the number is greater or lower than 10.

num=30
if num>10:
  print("Num is greater than 10")
elif num<10:
  print("Num is samller than 10")

Enter fullscreen mode Exit fullscreen mode

First you think only how to get the input.So to create Variable.
num=10
Ok now we got the number.
Then you think how to check the number is greater than 10 only now you dont think about how to check lower.
if num>10:
print("Num is greater than 10")
Then you think how to check lower.If you think whole program definetly you will be stuck.
5.Introduce a variables only when its simplifies the solution.
like question adding 1 and 5.
print(1+5).
6.Micro to Macro.
In every situation are not same you think about some ideas.
Example:
It is ok

print("1")
print("2")
print("3")
print("4")
print("5")

Enter fullscreen mode Exit fullscreen mode

But they asked output is 1 to 100.This steps make more time now we go to looping.

a=1
while a<=100:
  print(a)
  a=a+1

Enter fullscreen mode Exit fullscreen mode

7.Dry run before you run.
you write a program in paper first then code in monitor.Writing is helped to learn a mistake.
8.Every program has only three steps.
input-process-output.
9.Logic First,Syntax Next.
I think everyone know logic they only dont know how apply the logic into the program only. say 5 plus 5 . We say 10.they say solve the problem using programming language.Now we Nervous Right!

Top comments (0)