Yo! π€ Today is the day five of our course π The agenda for today is solving some fantastic questions based upon our learning this week. π
Summary of the week.
Day 1- We learnt what is Python, installed Python and wrote our very first hello world program. We also understood why Python is advantageous to other languages like C and Java.
Day 2- We learnt about Python statement types like assignments, expressions, declarations. We learnt how comments are written and the need of indentation. We then solved a few practice programs.
Day 3- We covered logical, relational, assignment and arithmetic operators, saw how they work. Then we understood the if-else syntax and solved a few problems on that.
Day 4- We learnt the For Loop in Python, how it differed from C, and solved some questions. (yes I admit they were boring)
Today I am gonna give you few exciting questions to solve, and show you a few myself. In the flow we will also learn printing style and code-structure. A few questions from over here are actually from interviews and coding tests. (No exaggeration here)
1)Here is an easy one to begin with. Write a program to give the output like shown below-
1
12
123
1234
12345
Solution-
for i in range(0,5):
for j in range(0,i+1):
print(j+1,end='')
print()
Explanation-As seen, there are two nested for loops. The second for loop has end variable i+1, where i is the running variable of the first loop.
You must have noticed the end parameter in the print statement. By default, the python's print function ends with a newline. We can modify it by giving an additional parameter to the function using end. We can end the print parameter using any character using it. The last print at the end of the bracket is the representative for the newline.
2) Write a program to check if numbers from 1-100 are prime or not
for a in range(0,100):
print(a,end="-")
IsPrime=0
for i in range (2,a//2):
if (a%i==0):
print("The number is composite ")
IsPrime=1
break
if (IsPrime==0):
print("The number is prime.")
As above, the indention must be clear when dealing with large nested blocks
Exercise
1) Actual interview question- Write a program for this output-
Please enter a character *
Please enter a number 3
*_
*_*_
*_*_*_
*_*_*_
*_*_
*_
2) User enters a character and a number. If the character is a vowel, then the the program's output is as given-
Please enter a character o
Please enter a number 4
o
o
oo
o
oo
ooo
o
oo
ooo
oooo
A bit about the course
I know, I am going a bit slow. May be too slow for some of you. But this is for the benifit of those who are here for the first time. The basic module of this course is made intentionally slow and elaborate. This week was a gentle intro to Python. In the coming weeks, I will cover all the details of the language. For those who already know coding basics, they can just skim through the blog and mull upon the exercises. The exercises provided will strengthen and reinforce the concepts. Moreover they are directly taken or similar to past coding tests from the interview panel...
Epilogue- We all know that neither me nor you have ever seen each other. Learning in remote environment is a difficult, and teaching is perhaps even more difficult. Teaching is never a one-way process. When a teacher teaches with pattern, he/she expects that the student must respond back. Either with doubts, remarks or nods of approval.
But friends, being remote, we cannot interact with each other. The only way we can connect is through the comments below. So I urge everyone to comment on the posts. Currently I am in doubt whether you all are understanding me or not. Should I speed up the pace or maybe explain more clearly? I am not getting any feedback from you. Any doubts, discussions, remarks or even a simple hi from you is a great source of motivation for me. So I look forward to your comments below...π
For those who have not yet made account in Dev.to, you can have a free easy sign-up using your mail or GitHub accounts. I would suggest the budding developers to create your GitHub free account right away. You would require to register sooner or later anyways
π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯π₯
Next day will begin from Tuesdayπ
, Monday is reserved for.... Surpriseπ₯ Follow me for updates...
Top comments (0)