Another week ended with busy works. Done exercises from "Learn Python 3 the Hardway" written by "Zed A. Shaw".
Here I am explaining FizzBizz program which prints every number from 1 to 20, print fizz when the number is multiple of 3, bizz when it's multiple of 5, and fizzbizz when it's multiple of 15, otherwise it just print the number.
First I defined function fizzbizz which takes a number as input. Printed numbers from 1 to 20 using for loop in range (1,n+1). Print fizz if it's a multiple of 3 and bizz when multiple of 5. Here we are using Modulo Operator "%" for implementing the program. Checking the number remainder with modulus. We can divide them and doesn't have any remainder, i.e., if the remainder is 0, then it's divisible by that particular number. And I stuck at multiple of 15 which is also a multiple of 3 and 5 and prints fizzbizz. I put the condition at the end, the code will never reach it, ending that iteration when the number is divisible by 3 or 5 move around the code to check it. Then if no conditions are true (not divisible by 3 or 5), just prints the number.
Below the fizzbizz program:
For multiple of 15 it doesn't print fizzbizz as you can see from the above output.
After putting the condition at first i got the output fizzbizz for multiple of 15.
That's all for this week. Thank you all for reading. Keep fetching for more updates...