This website collects cookies to deliver better user experience
Learning Python-Basic course: Day 7, Exercises and coding challenges⚔️
Learning Python-Basic course: Day 7, Exercises and coding challenges⚔️
Welcome 🖐️ Today's agenda is solving more interesting questions! ❤️ intricate patterns and mind-blowing sequences ✨
Let us now today solve some more questions 😀 on while loops and for loops. 😁 We will look at 2-3 sample questions followed by exercises and a coding challenge ⚔️.
Sample questions-
1) Write a program to print Fibonacci numbers.
a=0b=1print('0,1,',end="")for i inrange(0,10): a,b=b,b+a
print(b,end=",")
Simultaneous assignment of values
Note the second last line. This is the Python syntax for simultaneous assignment. This is equivalent to using a temp variable like-
temp=a
a=b
b=b+temp
This python shortcut comes very very handy while swapping two numbers to
2) Write a program to display times table from 1-10
for i inrange(1,11):for j inrange(1,11):print(i,"*",j,"=",j*i)print()