Skip to content

Commit 2dab082

Browse files
authoredFeb 23, 2024
Add files via upload
0 parents  commit 2dab082

36 files changed

+481
-0
lines changed
 

‎2D Lists & Nested Loops.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
number_grid = [
2+
[1, 2, 3],
3+
[4, 5, 6],
4+
[7, 8, 9],
5+
[0]
6+
]
7+
8+
print(number_grid[0][0])
9+
10+
print(number_grid[2][1])
11+
12+
print("Nested For Loop")
13+
14+
for row in number_grid:
15+
print(row)
16+
17+
for row in number_grid:
18+
for col in row:
19+
print(col)

‎Basic Translator.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def translate(phrase):
2+
translation = ""
3+
for letter in phrase:
4+
if letter in "AEIOUaeiou":
5+
translation = translation + ("g")
6+
else:
7+
translation = translation + letter
8+
return translation
9+
10+
print(translate(input("Enter a phrase")))
11+
12+
def translate(phrase):
13+
translation = ""
14+
for letter in phrase:
15+
if letter.lower() in "aeiou":
16+
if letter.isupper():
17+
translation = translation + ("H")
18+
else:
19+
translation = translation + ("h")
20+
else:
21+
translation = translation + letter
22+
return translation
23+
24+
print(translate(input("Enter a phrase")))

‎Better Calculator.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
num1 = float(input("Enter first number: "))
2+
op = input("Enter operator: ")
3+
num2 = float(input("Enter second number: "))
4+
5+
if op == "+":
6+
print(num1 + num2)
7+
elif op == "-":
8+
print (num1 - num2)
9+
elif op == "/":
10+
print(num1 / num2 )
11+
elif op == "*":
12+
print(num1*num2)
13+
else:
14+
print("Invalid Operator")

‎Building a Guessing Game.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
secret_word = "ralph"
2+
guess = ""
3+
guess_count = 0
4+
guess_limit = 3
5+
out_of_guesses = False
6+
7+
while guess != secret_word and not (out_of_guesses):
8+
if guess_count < guess_limit:
9+
guess = input("Enter guess: ")
10+
guess_count += 1
11+
12+
else:
13+
out_of_guesses = True
14+
if out_of_guesses:
15+
print("Out of Guesses, YOU LOSE!")
16+
else:
17+
print("You Win!")
18+

‎Chef.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Chef:
2+
3+
def make_chicken(self):
4+
print("The chef makes chicken")
5+
6+
def make_salad(self):
7+
print("The chef makes a salad")
8+
9+
def make_special_dish(self):
10+
print("The chef makes bbq ribs")

‎ChineseChef.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from Chef import Chef
2+
class ChineseChef(Chef):
3+
4+
def make_special_dish(self):
5+
print("The chef makes orange chicken")
6+
7+
def make_fried_rice(self):
8+
print("The chef makes fried rice")

‎Comments.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#This prints out a string
2+
print("Comments are fun")
3+
#This program is cool
4+
5+
6+
'''
7+
i can write as much text as l want
8+
multiple comments
9+
'''
10+
11+
#you can comment out a line of code so that you see if it is not the one giving you issues

‎Dictionaries.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
monthConversions ={
2+
"Jan": "January",
3+
"Feb": "February",
4+
"3": "March",
5+
"Apr": "April",
6+
"May": "May",
7+
"Jun": "June",
8+
"Jul": "July",
9+
"Aug": "August",
10+
"Sep": "September",
11+
"Oct": "October",
12+
"Nov": "November",
13+
"Dec": "December",
14+
}
15+
16+
print(monthConversions["Nov"])
17+
print(monthConversions.get("Dec"))
18+
print(monthConversions.get("Me", "Not a valid key"))
19+
print(monthConversions.get("3"))

‎For Loop.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
friends = ["Jim", "Karen", "Kevin"]
2+
for index in range(len(friends)) :
3+
print(friends[index])
4+
friends[0]
5+
6+
for index in range(5) :
7+
if index == 0:
8+
print(("first iteration"))
9+
else:
10+
print(("not first"))
11+
12+
for index in range(10) :
13+
print(index)
14+
15+
friends = ["Jim", "Karen", "Kevin"]
16+
for friend in friends :
17+
print(friend)
18+
19+
for index in range(3, 10) :
20+
print(index)
21+
22+
for letter in "Ralph Tashinga":
23+
print(letter)

‎IF Statements & Comparisons.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def max_num(num1, num2, num3):
2+
if num1 >= num2 and num1 >= num3:
3+
return num1
4+
elif num2 >= num1 and num2 >= num3:
5+
return num2
6+
else:
7+
return num3
8+
9+
print(max_num(3, 4,5))
10+

‎IF Statements.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
is_female = True
2+
is_tall = True
3+
4+
if is_female:
5+
print("You are a female")
6+
else:
7+
print("You are not a female")
8+
9+
if is_female or is_tall:
10+
print("You are a female or tall or both")
11+
else:
12+
print("You are neither female nor tall")
13+
14+
if is_female and is_tall:
15+
print("You are a tall female")
16+
else:
17+
print("You are either not female or not tall or both")
18+
19+
if is_female and is_tall:
20+
print("You are a tall female")
21+
elif is_female and not(is_tall):
22+
print("You are a short female")
23+
elif not(is_female) and is_tall:
24+
print("You are not female but tall")
25+
else:
26+
print("You are not a female and not tall ")

‎Inheritance.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from Chef import Chef
2+
from ChineseChef import ChineseChef
3+
4+
myChef = Chef()
5+
myChef.make_special_dish()
6+
7+
myChineseChef = ChineseChef()
8+
myChineseChef.make_special_dish()

‎Lists.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
friends = ["Ralph", "Tashinga", "Rutendo", "Fortunate", "Olivia"]
2+
print(friends)
3+
print(friends[0])
4+
print(friends[2])
5+
print(friends[-1])
6+
print(friends[-2])
7+
print(friends[1:])
8+
print(friends[1:3])
9+
10+
friends[1] = "Alice"
11+
print(friends[1])
12+
print(friends)
13+
14+
print("LIST FUNCTIONS")
15+
lucky_numbers = [40, 8, 15, 16, 23, 42 ]
16+
friends = ["Ralph", "Tashinga", "Rutendo", "Fortunate", "Olivia"]
17+
print(friends)
18+
19+
friends.sort()
20+
print(friends)
21+
22+
lucky_numbers.sort()
23+
print(lucky_numbers)
24+
25+
lucky_numbers.reverse()
26+
print(lucky_numbers)
27+
28+
friend2 =friends.copy()
29+
print(friend2)
30+
31+
friends.extend(lucky_numbers)
32+
print(friends)
33+
friends.append("Paul")
34+
print(friends)
35+
36+
friends.insert(1, "Karen")
37+
print(friends)
38+
39+
friends.remove("Ralph")
40+
print(friends)
41+
42+
print(friends.index("Rutendo"))
43+
44+
print(friends.count("Fortunate"))
45+
46+
friends.pop()
47+
print(friends)
48+
49+
50+
friends.clear()
51+
print(friends)

‎Multiple Choice Quiz.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from Question import Question
2+
3+
question_prompts = [
4+
"What color are apples?\n(a) Red/Green\n (b) Purple\n(c) Orange\n\n",
5+
"What color are bananas?\n(a) Teal\n (b) Magenta\n (c) Yellow\n\n",
6+
"What color are strawberries?\n(a) Yellow\n (b) Red\n (c) Blue\n\n"
7+
]
8+
9+
questions = [
10+
Question(question_prompts[0], "a"),
11+
Question(question_prompts[1], "c"),
12+
Question(question_prompts[2], "b"),
13+
]
14+
15+
def run_test(questions):
16+
score = 0
17+
for question in questions:
18+
answer = input(question.prompt)
19+
if answer == question.answer:
20+
score += 1
21+
print("You got " + str(score) + "/" + str(len(questions)) + " correct")
22+
23+
run_test(questions)

‎Question.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Question:
2+
def __init__(self, prompt, answer):
3+
self.prompt = prompt
4+
self.answer = answer

‎Reading Files.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#r is read, l only want to read the information in the file
2+
employee_file = open("employees .txt", "r")
3+
4+
#print(employee_file.readable())
5+
print(employee_file.readlines())
6+
7+
employee_file.close()
8+
9+
#w is write, l want to write and change some information
10+
#open("employees.docx", "w")
11+
12+
#a is append, append information onto the file, add more information only to the end of the file
13+
#open("employees.docx", "a")
14+
15+
# r+ , you can read and write
16+
#open("employees.docx", "r+")

‎Return Statement.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def cube(num):
2+
return num*num*num
3+
4+
print(cube(3))
5+
6+
result = cube(4)
7+
print(result)
8+
9+

‎Student.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Student:
2+
3+
def __init__(self, name, major, gpa, is_on_probation):
4+
self.name = name
5+
self.major = major
6+
self.gpa = gpa
7+
self.is_on_probation = is_on_probation
8+
9+
def on_honor_roll(self):
10+
if self.gpa >= "3.5":
11+
return True
12+
else:
13+
return False

‎Try Except.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
4+
try:
5+
value = 10 / 0
6+
number = int(input("Enter a number: "))
7+
print(number)
8+
#don't just use except without a specific error because its just too broad
9+
except ZeroDivisionError as err:
10+
print(err)
11+
except ValueError:
12+
print("invalid input")

‎Tuples.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
print("This below is a list and the list can be updated")
2+
coordinates = [4, 5]
3+
coordinates[1] = 10
4+
print(coordinates[1])
5+
6+
print("Now tuples cannopt be updated")
7+
coordinates = (4, 5)
8+
print(coordinates[1])
9+
10+
print("tuples inside a list")
11+
coordinates=[(4, 5), (6, 7), (80, 34)]
12+
coordinates[1] = 10
13+
print(coordinates)

‎Variables&DataTypes.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
character_name = "Ralph"
2+
character_age = "27"
3+
is_male = True
4+
print("There once was a man named " + character_name + ", ")
5+
print("he was " + character_age + " years old. ")
6+
7+
character_name = "Tashinga"
8+
print("He really liked the name " + character_name + ", ")
9+
print("but didn't like being " + character_age + ".")

‎While Loop.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
i = 1
2+
while i <= 10:
3+
print(i)
4+
i = i + 1
5+
print ("using the operator differently")
6+
x = 1
7+
while x <= 10:
8+
print(x)
9+
x += 1

‎basic calculator.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
print("INTEGERS ONLY")
2+
num1 = input("Enter a number: ")
3+
num2 = input("Enter another number: ")
4+
result = int(num1) + int(num2)
5+
print(result)
6+
7+
print("with commas")
8+
num3 = input("Enter a number: ")
9+
num4 = input("Enter another number: ")
10+
result = float(num3) + float(num4)
11+
print(result)

‎classes & objects.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from Student import Student
2+
3+
student1 = Student("Jim", "Business", "3.1", False)
4+
student2 = Student("Pam", "Art", "2.5", True)
5+
6+
print(student1.name)
7+
print(student1.gpa)
8+
9+
print(student2.name)
10+
print(student2.gpa)
11+
12+
print(student1.on_honor_roll())

‎employees .txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Jim � Salesman
2+
Dwight � Salesman
3+
Pam � Receptionist
4+
Michael � Manager
5+
Oscar - Accountant
6+
Toby - Human Resources
7+
Kelly - Customer Service

‎exponent function.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
print(2**3)
2+
3+
def raise_to_power (base_num, pow_num):
4+
result = 1
5+
for index in range (pow_num):
6+
result = result * base_num
7+
return result
8+
9+
print(raise_to_power(3, 4))
10+

‎functions.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def sayhi():
2+
print("Hello User")
3+
4+
print("Top")
5+
sayhi()
6+
print("Bottom")
7+
8+
def say_hie(name, age):
9+
print("Hello " + name+ ", you are " + age)
10+
11+
say_hie("Ralph", "35")
12+
13+
def say_hie(name, age):
14+
print("Hello " + name+ ", you are " + str(age))
15+
16+
say_hie("Ralph", 35)

‎gettinginputfromusers.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = input("Enter your name: ")
2+
age = input("Enter your age: ")
3+
print("Hello " + name+ "!" " You are " +age )

‎helloworld.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello World")

‎mad libs game.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
print("Roses are red")
2+
print("Violets are blue")
3+
print("I love you")
4+
5+
color = input("Enter a color: ")
6+
plural_noun = input("Enter a plural noun: ")
7+
celebrity = input("Enter a celebrity: ")
8+
9+
print("Roses are " +color)
10+
print(plural_noun + " are blue")
11+
print("I love " +celebrity)

‎modules & Pip.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import useful_tools
2+
3+
print(useful_tools.roll_dice(10))
4+
5+

‎shape.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
print(" /|")
2+
print(" / |")
3+
print(" / |")
4+
print("/___|")

‎useful_tools.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import random
2+
3+
feet_in_mile = 5280
4+
meters_in_kilometer = 1000
5+
beatles = ["John Lennon", "Paul McCartney", "George Harrison", "Ringo Star"]
6+
7+
def get_file_ext(filename):
8+
return filename[filename.index(".") + 1:]
9+
10+
def roll_dice(num):
11+
return random.randint(1, num)

‎workingwithnumbers.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
print(7.0964)
2+
print(-7)
3+
print(3+3.6)
4+
print(10-5)
5+
print(2*2)
6+
print(10/2)
7+
print(3*(4+5))
8+
print(3*4 + 5)
9+
print(10%3)
10+
my_num = 5
11+
print(my_num)
12+
print(str(my_num) + " my favorite number")
13+
print(abs(my_num))
14+
print(pow(2, 2))
15+
print(max(8, 3))
16+
print(min(90, 10))
17+
print(round(3.7))
18+
print(round(3.4))
19+
20+
from math import *
21+
22+
print(floor(3.7))
23+
print(ceil(3.7))
24+
print(sqrt(36))

‎workingwithstrings.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
print("Ralph Tashinga")
2+
print("Rutendo\nFortunate")
3+
print("Rutendo\"Fortunate\"")
4+
print("Ralph\\Tashinga")
5+
phrase = "Ralph Nyoni "
6+
print(phrase + "is cool")
7+
print(phrase.lower())
8+
print(phrase.upper())
9+
print(phrase.isupper())
10+
print(phrase.upper().isupper())
11+
print(len(phrase))
12+
print(phrase[3])
13+
print(phrase.index("Nyoni"))
14+
print(phrase.replace("Nyoni", "Tashinga"))

‎writing to files.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
employee_file = open("employees .txt", "a")
2+
employee_file.write("Toby - Human Resources")
3+
employee_file.write("\nKelly - Customer Service")

0 commit comments

Comments
 (0)
Please sign in to comment.