Tutorial 5
Tutorial 5
234128 – Introduction to
Computing with Python
expression
While False
block
True
Statements
Negative
number?
Stop
looping!
234128 – Introduction to Computing with Python 16
Exercise 3 – Count Digits in Number
• Write a program which gets a number x and digit d as input.
• The program finds how many times the digit d appear in number
x.
• You may assume all the numbers are positive.
• Examples:
- The digit 1 appears two times in 215610
- The digit 0 appears one time in 10
• Empty list?
True if user
entered ‘y’ or ‘n’
Equivalent to:
if x==‘n’ or x==‘y’
string (Empty string – behaves like Traceback (most recent call last):
• Split: Sentence → Words ['You cannot end a sentence with ', '
', ' ', ' is a conjunction.']