A number inside a random number
Task
The computer generates a random number from the interval (100,000,000; 200,000,000) and the user enters a number to search for in it. The program prints whether the searched number occurs in the generated one and how many times.
A random number cannot be tested by comparing output, so split the program into two functions - the tests call them directly:
vygeneruj()returns a random whole number from the interval (100,000,000; 200,000,000) without the end points,pocet_vyskytov(velke, hladane)gets two whole numbers and returns how many times the digits ofhladaneoccur in the digits ofvelke(occurrences do not overlap, as with thecountmethod).
The main program is already done under if __name__ == "__main__": - it does not run during the tests, but you can try it with Run.
What the program should do
pocet_vyskytov(152341523, 15) returns 2.
Examples
Call
print(pocet_vyskytov(152341523, 15))
Expected output
2
Call
cisla = [vygeneruj() for _ in range(300)] print(all(type(c) == int and 100000000 < c < 200000000 for c in cisla)) print(len(set(cisla)) > 1)
Expected output
True True
After you submit, 3 hidden tests will also check your solution: a single digit, not found, searching the whole number.
Python starts the first time you run code.
Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.
Input (stdin)
Each line = one call to input().
Output
Hints
Try it yourself first. Each hint reveals a little more - and lowers the reward a little.
Signed out, hints are free - but no XP is awarded either.
Solution
The solution unlocks after the last hint.