Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

TABLE OF CONTENTS

INTRODUCTION………………………………………………………………….. 2
PROJECT OBJECTIVE AND DESIGN PROCEDURES …………………………… 2-3
CHALLENGES AND SOLUTIONS……………………………………………… 4
CONCLUSION………………………………………………………………………… 4
REFERENCES……………………………………………………………………… 5

1|Page
INTRODUCTION

PROJECT OBJECTIVES
There are two main objectives to carry out this project, firstly is to find or implement a python
code to determine how many of the numbers between 1 and 10 000 contains digit 3 and
secondly is to implement a python code that will write a function called first_diff that is given
two strings and returns the first location in which the strings differ. If the strings are identical, it
should return -1.
DESIGN PROCEDURES

 First of all, a flowchart was designed to help in the simplification of a code, the flowchart
is as follows:

Start

N=n/10
Read n

Count=0 n!=0

Print c stop

2|Page
The following code was implemented to find or implement a python code to determine how
many of the numbers between 1 and 10 000 contains digit 3, first of all the program will print
out the sum of numbers with digit 3 and later it will print out all the numbers with 3 if we run or
execute the code in python using either PyCharm or visual studio code using the following code:
from tkinter import*
count=0
search_for_number=3
start_number=1
end_number=10000

for i in range(start_number,end_number+1):
count +=int(str(i).count(str(search_for_number)))
print(f"there are {count} number {search_for_number} in range {start_number}-
{end_number}")

print("Thus the number containing digit 3 from 1 to 10000 are as follows:")


def index(st, ch):
for i in range(len(st)):
if (st[i] == ch):
return i;
return -1
def printNumbers(lastnumber, digit):
st = "" + str(digit)
ch = st[0]
for i in range(0, lastnumber+ 1, 1):
st = ""
st = st + str(i)
if (i == digit or index(st, ch) >= 0):
print(i, end=" ")
if __name__ == '__main__':
lastnumber = 10000
digit = 3
printNumbers(lastnumber, digit)

 secondly, the following code was implemented to carry out the second objective of the
project, the code will consist of a function called first_diff that is assigned with two
strings and will return the first location in which the strings differ, and the strings are
identical, it should return ( -1) in python using either visual studio code or PyCharm, the
code is as follow:
from tkinter import*
def first_diff(s1, s2):
return min([c for c in range((min([len(s1), len(s2)]))) if s1[c]!=s2[c]],
default=-1)
output_of_function=first_diff('hello','hello')
print(output_of_function)

3|Page
CHALLENGES AND SOLUTIONS
An indent error was one of the common challenges experienced during the coding process.
Having not put the colons at the end of a certain for loop, the next line will not be indented
correctly and therefore the program will not run.
The solution to all those errors was taking care of for loops first by putting the required colons.
The next line after for loops gets indented correctly when colons are in place.

CONCLUSION
While solving this project, progress was made to solve a number of similar problems in order to
understand the main project problems. Solution to each problem by ourselves was the most
important part of the project and this provided us with more experiences which will help us in
the future with tackling more complex problems in programming.
Some important things was learnt including the design of a good program architecture and
converting real life situations into an efficient code, and how to write a good looking easily
readable and understandable as well as time and memory efficient codes.

4|Page
REFERENCES
Practical_Introduction_to_Python_Programming_Heinold.
http://www.effbot.org/tkinterbook/entry.htm
http://www.effbot.org/tkinterbook/entry.htm

5|Page

You might also like