Python Foundation Classroom Series – 14/Aug/2021

Foundations continued

  • Lets try to solve the following problem
    • Sum of all the numbers on the vehicle number plate
    9394 => 7
    9235 => 1
    4545 => 9
    
  • Lets try to speak the language
number = 9394
remainder = number%10 # 4
number = number //10 # 939
remainder = remainder + number%10 # 4+9
number = number //10 # 93
remainder = remainder + number%10 # 13 + 3
number = number //10 # 9
remainder = remainder + number%10 # 16+9
number = number //10 # 0
number = remainder #25
remainder = number%10 # 5
number = number //10 # 2
remainder = remainder + number%10 # 5+2
number = number //10 # 0

  • To solve the problem of writing same expressions multiple times we have looping controls and to execute some lines of code based on conditions we have conditional statements
1. number = 9394
2. remainder = 0
3. until number != 0 # execute below lines
4.    remainder = remainder + number%10 # 0+4+9+3+9 # 0+2+5
5.     number = number // 10 #939 93 9 0

6. if remainder <= 9 then
7.    print remainder
8. else
9.   number = remainder
10.  goto line no 2

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin