Programing For Engineers Mini Project 1
Programing For Engineers Mini Project 1
1.We know that plagiarism is wrong. Plagiarism is to use another’s work and pretend that it is my own.
2.We declare that the solutions to this assessment are my own work.
3.We have not allowed and will not allow anyone to copy my work with the intention of passing it off as his or her own work.
I acknowledge that copying someone else’s solution (or part of it) is wrong and declare that my solutions are my own work.
_hhamutenyat_ __20/06/2021__
Student-1 Signature Date
______sherman_________ ___20/06/2021__
Student-2 Signature Date
220040427_TIOFELUS HAMUTENYA
220053642_HERMAN SHEELONGO
NAMIBIA UNIVERSITY OF SCIENCE AND TECHNOLOGY
TABLE OF CONTENTS
INTRODUCTION………………………………………………………………….. 2
PROJECT OBJECTIVE …………………………………………………………… 3
DESIGN PROCEDURE …………………………………………………………… 4-6
CHALLENGES AND SOLUTIONS……………………………………………… 7
CONCLUSION………………………………………………………………………… 8
REFERENCES…………………………………………………………………………. 9
1|Page
INTRODUCTION
According to the latest TIOBE Programming Community Index, python is regarded as one of the
top 10 popular programing language of 2017.As per the sources extracted from the internet,
Python was first implemented by Guido van Rossum at Centrum Wiskuinde & Informatica
(CWI), Netherlands in 1980s.He was a successor to ABC programming language, which was
inspired by SETL, capable of exception handling and interfacing with the Amoeba operating
systems. Python was developed in order to develop desktop GUI applications, websites and also
web application, as it became a high-level programming language, it allowed people to focus on
a core functionality of the application by taking care of common programming tasks, where as
the simplification of the syntax allowed to keep the code base readable and applications
maintainable.
There are several integrated development environments in python such PyCharm, VScode and
many more others of which are differentiated by the performance capability. In terms
performance it is believed that VScode easily beats PyCharm but because PyCharm has many
more plugins, user-friendly and more advance, many coders choose to use PyCharm in caring
out their projects, lecturer students at institution etc.
2|Page
PROJECT 0BJECTIVES
There are four 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. Thirdly, the digital root of a number n is obtained as follows: Add up the digits
n to get a new number. Add up the digits of that to get another new number. Keep doing this
until you get a number that has only one digit. That number is the digital root.
For example, if n = 45893, we add up the digits to get 4 + 5 + 8 + 9 + 3 = 29. We then add up.
the digits of 29 to get 2 + 9 = 11. We then add up the digits of 11 to get 1 + 1 = 2. Since 2 has
only one digit, 2 is our digital root.
Write a function that returns the digital root of an integer n. [Note: there is a shortcut, where
the digital root is equal to n mod 9, but do not use that here. Lastly was to Write a program that
creates the list [1,11,111, 1111,...,111...1], where the entries have an ever-increasing number of
ones, with the last entry having 100 ones.
3|Page
DESIGN PROCEDURES
First of all, 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:
import tkinter as tk
window = tk.Tk()
fb2 = tk.Label(
window, text="Numbers between 1 and 10,000 contain digit 3 are:",
font="times 20")
fb2.pack()
count = 0
for i in range(1, 10001):
x = str(i)
for j in range(0, len(x)):
if(x[j] == '3'):
count += 1
break
window.mainloop()
secondly, the following code was implemented in python 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:
import tkinter as tk
from tkinter import *
def first_diff(str1,str2):##This is the first_diff function which take two
strings as parameter
n=min(len(str1),len(str2))## Taking minimum length of those two strings
for i in range(0,n):##Start iterating both string
if(str1[i]!=str2[i]):##If for any index the character of string 1
doesn't matchs with string2's character return that index
4|Page
return i
if(len(str1)>len(str2)):##If length of string 1 is greater than string 2
if till now there is no mismatch then return len of second string
return len(str2)
if(len(str2)>len(str1)):##If length of string 2 is greater than string 1
if till now there is no mismatch then return len of first string
return len(str1)
return -1 ## If both string is identical then return -1
Thirdly, the following code implement in python using PyCharm will find the digital root
of a number n which is obtained as follows: Add up the digits n to get a new number.
Add up the digits of that to get another new number. Keep doing this until you get a
number that has only one digit. That number is the digital root.
For example, if n = 45893, we add up the digits to get 4 + 5 + 8 + 9 + 3 = 29. We then
the digits of 29 to get 2 + 9 = 11. We then add up the digits of 11 to get 1 + 1 = 2. Since
only one digit, 2 is our digital root.
from tkinter import *
root = Tk()
root.geometry('400x300')
root.title("Digital Root Calculator")
root.resizable(False, False)
def calc_dig_root():
try:
digit = int(entry1.get())
while digit >= 10:
Sum = 0
for i in str(digit):
Sum += int(i)
digit = Sum
label2.config(text=digit)
except:
varname2.set("Something is wrong !")
# ENTRY BOX
varname1 = StringVar()
5|Page
entry1.place(x=180, y=45)
entry1.focus()
varname2 = StringVar()
# LABEL
label1 = Label(root, font=20, text="Enter the number : ")
label1.place(x=5, y=40)
# BUTTONS
root.mainloop()
Lastly, the following code was implemented to create the list [1,11,111, 1111,...,111...1],
where the entries have an ever-increasing number of ones, with the last entry having
100 ones.
from tkinter import *
mainloop()
6|Page
CHALLENGES AND SOLUTIONS
During coding it was a common thing to get the invalid syntax error. This was mainly caused by
not using/putting the correct punctuations where they are supposed to be, example not putting
the colons (:) at the end of for loops.
An indent error was also one of the common challenges experienced during the coding process.
After not putting 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.
7|Page
CONCLUSION
While solving this project problems, we made our progress by solving 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 we learnt include designing 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.
8|Page
REFERENCES
!!!A_Practical_Introduction_to_Python_Programming_Heinold.
http://www.effbot.org/tkinterbook/entry.htm
http://www.effbot.org/tkinterbook/entry.htm
Mark Lutz – Learning Python, 5th Edition -2013.
9|Page