Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/BCS-2021.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# BCS-2021
This repository is created to collect the assignment solutions for the subject CSC1102 Principles of Programming for the students of Bachelors of Computer Science Year I, in the faculty of Computing and Informatics, MUST.
## Group 6 Members

1. AKANYIJUKA GASTON 2020/BCS/066/PS
2. KATUSHABE MOREEN 2020/BCS/034/PS
3. NANZIRI CHARLOTTE HELGA 2020/BCS/090/PS
4. OMARE DANIEL 2020/BCS/057/PS
5. BEILEL AUGUSTINE 2019/BCS/022/PS
3 changes: 3 additions & 0 deletions src/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/.idea/src.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/chapter2/exercise2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = input("what is your name?\n")
print("YOUR WELCOME", name)
4 changes: 4 additions & 0 deletions src/chapter2/exercise3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Hours = float(input("Enter Hours"))
Rate = float(input("Enter Rate"))
Gross_Pay = Hours * Rate
print(Gross_Pay)
Binary file added src/chapter2/exercise4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/chapter2/exercise5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x = float(input("Enter the temperature in degrees C :"))
y = (((x * 9) / 5) + 32) # y is the temperature in degrees Fahrenheit
print(y, "°F")
6 changes: 6 additions & 0 deletions src/chapter2/exercise6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
x1 = float(input("enter x1 :"))
x2 = float(input("enter x2 :"))
y1 = float(input("enter y1 :"))
y2 = float(input("enter x1 :"))
d = ((((x2 - x1) ** 2) + ((y2 - y1) ** 2)) ** 0.5)
print(d)
16 changes: 16 additions & 0 deletions src/chapter2/exercise7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
c = float(input("Enter Amount Between 0-99 :"))
print(c // 20, "Twenties")
c = c % 20
print(c // 10, "Tens")
c = c % 10
print(c // 5, "Fives")
c = c % 5
print(c // 1, "Ones")
c = c % 1
print(c // 0.25, "Quarters")
c = c % 0.25
print(c // 0.1, "Dimes")
c = c % 0.1
print(c // 0.05, "Nickles")
c = c % 0.05
print(c // 0.01, "Pennies")
6 changes: 6 additions & 0 deletions src/chapter2/exercise8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
t = float(input("Enter t"))
C = float(input("Enter C"))
r = float(input("Enter r"))
n = float(input("Enter n"))
p = round(C * (1 + (r / n)) ** (t * n), 2) # The value of "p" already is rounded off to 2 dp using the round function
print(p)
3 changes: 3 additions & 0 deletions src/chapter3/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/chapter3/.idea/chapter3.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/chapter3/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/chapter3/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/chapter3/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/chapter3/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/chapter3/excercise1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
x = float(input("enters hours"))
y = float(input("enters rate"))
z = (x * y) # this is the pay for hours of work below or equal to 40
q = y * 40
m = (1.5 * (x - 40) * y) # m is the extra hours worked beyond the 40 hours .
r = (q + m) # this is the pay for hours of work above 40
if x <= 40:
print(z)
elif x > 40:
print(r)
13 changes: 13 additions & 0 deletions src/chapter3/excercise2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
try:
x = float(input("enters hours"))
y = float(input("enters rate"))
z = (x * y) # this is the pay for hours of work below or equal to 40
q = y * 40
m = (1.5 * (x - 40) * y) # m is the extra hours worked beyond the 40 hours .
r = (q + m) # this is the pay for hours of work above 40
if x <= 40:
print(z)
elif x > 40:
print(r)
except:
print("ERROR, PLEASE ENTER NUMERIC INPUT")
18 changes: 18 additions & 0 deletions src/chapter3/excercise3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
try:
score = float(input('enter score'))
# A program that prompts a user to enter a score from 0 to 1 and prints the corresponding grade
if 0 <= score < 0.6:
print(score, 'F')
elif 0.6 <= score < 0.7:
print(score, 'D')
elif 0.7 <= score < 0.8:
print(score, 'C')
elif 0.8 <= score < 0.9:
print(score, 'B')
elif 0.9 <= score <= 1:
print(score, 'A')
else:
print('error, out of range')

except:
print("INVALID ENTRY")
10 changes: 10 additions & 0 deletions src/chapter3/excercise4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try:
age = int(input('enter age'))
if age >= 18:
print('you can vote') # prints out only people who can vote
elif 0 <= age <= 17:
print('too young to vote')
elif age < 0:
print('you are a time traveller')
except:
print('error, please enter a digit')
15 changes: 15 additions & 0 deletions src/chapter3/excercise5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
""""A PROGRAM THAT PROMPTS THE USER FOR
THE NUMBER OF PEOPLE ATTENDING THEIR WEDDING AND PRINTS THE CORRESPONDING PRICE IN THE CONSOLE"""""
try:
a = int(input('Number of guests'))
if 0 < a <= 50:
print('price =$4000')
elif 50 < a <= 100:
print('price = $10000')
elif 100 < a <= 200:
print('price = $15000')
elif a > 200:
print('price = $20000')
except:
print('error, please enter a digit')

Binary file added src/chapter3/exercise6.jpeg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/chapter3/exercise7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
try:
g = input('enter job location')
b = int(input('enter pay'))
if g.upper() == 'MBARARA' and b <= 4000000: # (. upper) converts all the locations into uppercase
print('No Thanks, I can find something better')
elif g.upper() == 'MBARARA' and b > 4000000:
print('I can work with this')
elif g.upper() == 'KAMPALA' and b >= 10000000:
print('I can work with this')
elif g.upper() == 'KAMPALA' and b < 10000000:
print('No Way!')
elif g.upper() == 'SPACE' and b >= 0:
print('Without doubt, I will work')
elif b >= 6000000: # g==other districts and b>=6000000
print('I will surely work')
else:
print('No thanks, I can find something better')
except:
print('invalid entry')
Binary file added src/chapter4/exercise1.pdf
Binary file not shown.
20 changes: 20 additions & 0 deletions src/chapter4/exercise2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
c = (input('ENTER INITIAL AMOUNT OF INVESTMENT >>'))
n = (input('ENTER NUMBER OF YEARS THE INTEREST IS COMPOUNDED PER YEAR>>'))
r = (input('ENTER YEARLY RATE OF INTEREST>> '))
t = (input('ENTER NUMBER OF YEARS UNTIL MATURATION>>'))


def investment(w, x, y, z):
try:
w = float(c)
x = float(n)
y = float(r)
z = float(t)
p = round(w * (1 + (y / x)) ** (z * x), 2) # p is rounded to 2 dp using the round function
return p
except ValueError:
return "INVALID ENTRY"


p = investment(c, r, n, t)
print(p)
Binary file added src/chapter4/exercise3.pdf
Binary file not shown.
Binary file added src/chapter4/exercise4.pdf
Binary file not shown.
21 changes: 21 additions & 0 deletions src/chapter4/exercise6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
x = (input("enters hours"))
y = (input("enters rate"))


def compute_pay(hours, rate):
"""The try block ensures that the user enters a
value between from 0-1 otherwise an error message pops up"""
try:
hours = float(x)
rate = float(y)
if hours <= 40:
pay= float(hours * rate)
else:
pay = float(40 * rate + (hours - 40) * 1.5 * rate)
return pay
except ValueError:
return "INVALID ENTRY"


pay = compute_pay(x, y)
print(pay)
27 changes: 27 additions & 0 deletions src/chapter4/exercise7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# A program that prompts a user to enter a score from 0 to 1 and prints the corresponding grade
s = (input('enter score'))


def compute_grade(score):
# this makes sure that the user enters only float values otherwise an error message pops up
try:
score = float(s)
if 0 <= score < 0.6:
print(score, 'F')
elif 0.6 <= score < 0.7:
print(score, 'D')
elif 0.7 <= score < 0.8:
print(score, 'C')
elif 0.8 <= score < 0.9:
print(score, 'B')
elif 0.9 <= score <= 1:
print(score, 'A')
else:
print('error, out of range')
return "grade"
except ValueError:
return "INVALID ENTRY"


grade = compute_grade(s)
print(grade)
18 changes: 18 additions & 0 deletions src/chapter5/excercise1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
try:
total = 0
count = 0
# the user will be able to input numbers repeatedly
while True:
x = input('enter a number')
# when done is entered, the loop will be broken
if x == 'done':
break
x = int(x)
# we are finding the total, count and average of the numbers entered
total = total + x
count = count + 1
average = total / count
print('done!')
print(count, total, average)
except:
print('Invalid Input')
16 changes: 16 additions & 0 deletions src/chapter5/exercise1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
total = 0
count = 0
average = 0

while True:
try:
inp = input("Enter a number: ")
if inp == "done":
break
value = float(inp)
total = value + total
count = count + 1
average = total / count
except ValueError:
print("Invalid input.")
print(total, count, average)
Loading