├── .idea ├── .gitignore ├── harry.iml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── Calculator.py ├── RPC.py ├── __pycache__ ├── RPC.cpython-312.pyc ├── datatype.cpython-312.pyc ├── functions.cpython-312.pyc ├── module.cpython-312.pyc └── string.cpython-312.pyc ├── area.py ├── arrays.py ├── assignment.py ├── car.py ├── classesobjects.py ├── controlstatement.py ├── course.py ├── datatype.py ├── encapsulation.py ├── exceptions.py ├── functions.py ├── inheritance.py ├── introduction.py ├── loops.py ├── mathmodule.py ├── module.py ├── oop1.py ├── operators.py ├── polymorphism.py ├── string.py ├── useinputoutput.py └── variables.py /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/harry.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 26 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Calculator.py: -------------------------------------------------------------------------------- 1 | #first number 2 | #operator 3 | #second number 4 | #display result 5 | 6 | 7 | num1 = int(input("enter first number: ")) 8 | operator = int(input("enter operator. Either (1.Addition/2. Subtraction/3.Multiplication/4.Division): ")) 9 | num2 = int(input("Enter the second number: ")) 10 | 11 | 12 | if operator == 1: 13 | print("result = ",num1 + num2) 14 | elif operator == 2: 15 | print("result = ",num1 - num2) 16 | elif operator == 3: 17 | print("result = ",num1 * num2) 18 | elif operator == 4: 19 | print("result = ",num1 / num2) 20 | 21 | 22 | -------------------------------------------------------------------------------- /RPC.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | # Print multiline instruction 4 | print('Winning rules of the game ROCK PAPER SCISSORS are:\n' 5 | + "Rock vs Paper -> Paper wins \n" 6 | + "Rock vs Scissors -> Rock wins \n" 7 | + "Paper vs Scissors -> Scissors wins \n") 8 | 9 | while True: 10 | 11 | print("Enter your choice \n 1 - Rock \n 2 - Paper \n 3 - Scissors \n") 12 | 13 | # Take the input from user 14 | choice = int(input("Enter your choice: ")) 15 | 16 | # Looping until user enters valid input 17 | while choice > 3 or choice < 1: 18 | choice = int(input('Enter a valid choice please: ')) 19 | 20 | # Initialize value of choice_name variable corresponding to the choice value 21 | if choice == 1: 22 | choice_name = 'Rock' 23 | elif choice == 2: 24 | choice_name = 'Paper' 25 | else: 26 | choice_name = 'Scissors' 27 | 28 | # Print user choice 29 | print('User choice is:', choice_name) 30 | print("Now it's Computer's Turn...") 31 | 32 | # Computer chooses randomly any number among 1, 2, and 3 33 | comp_choice = random.randint(1, 3) 34 | 35 | # Initialize value of comp_choice_name variable corresponding to the choice value 36 | if comp_choice == 1: 37 | comp_choice_name = 'Rock' 38 | elif comp_choice == 2: 39 | comp_choice_name = 'Paper' 40 | else: 41 | comp_choice_name = 'Scissors' 42 | 43 | print("Computer choice is:", comp_choice_name) 44 | print(choice_name, 'vs', comp_choice_name) 45 | 46 | # Determine the winner 47 | if choice == comp_choice: 48 | result = "DRAW" 49 | elif (choice == 1 and comp_choice == 2) or (comp_choice == 1 and choice == 2): 50 | result = 'Paper' 51 | elif (choice == 1 and comp_choice == 3) or (comp_choice == 1 and choice == 3): 52 | result = 'Rock' 53 | elif (choice == 2 and comp_choice == 3) or (comp_choice == 2 and choice == 3): 54 | result = 'Scissors' 55 | 56 | # Print the result 57 | if result == "DRAW": 58 | print("<== It's a tie! ==>y") 59 | elif result == choice_name: 60 | print("<== User wins! ==>") 61 | else: 62 | print("<== Computer wins! ==>") 63 | # Ask if the user wants to play again 64 | print("Do you want to play again? (Y/N)") 65 | ans = input().lower() 66 | if ans == 'n': 67 | break 68 | 69 | # After coming out of the while loop, print thanks for playing 70 | print("Thanks for playing!") -------------------------------------------------------------------------------- /__pycache__/RPC.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myusercloud/rpc/d7719a304aaabdb4eb4655f885ba7a35ed47f209/__pycache__/RPC.cpython-312.pyc -------------------------------------------------------------------------------- /__pycache__/datatype.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myusercloud/rpc/d7719a304aaabdb4eb4655f885ba7a35ed47f209/__pycache__/datatype.cpython-312.pyc -------------------------------------------------------------------------------- /__pycache__/functions.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myusercloud/rpc/d7719a304aaabdb4eb4655f885ba7a35ed47f209/__pycache__/functions.cpython-312.pyc -------------------------------------------------------------------------------- /__pycache__/module.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myusercloud/rpc/d7719a304aaabdb4eb4655f885ba7a35ed47f209/__pycache__/module.cpython-312.pyc -------------------------------------------------------------------------------- /__pycache__/string.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myusercloud/rpc/d7719a304aaabdb4eb4655f885ba7a35ed47f209/__pycache__/string.cpython-312.pyc -------------------------------------------------------------------------------- /area.py: -------------------------------------------------------------------------------- 1 | #area=len*wid 2 | length = float(input("Enter the length: ")) 3 | width = float(input("Enter the width: ")) 4 | 5 | area = length * width 6 | print("the area is:",area) -------------------------------------------------------------------------------- /arrays.py: -------------------------------------------------------------------------------- 1 | courses = ["MIT","Python","Android"] 2 | print(courses) 3 | #accessing an element 4 | print(courses[1]) 5 | 6 | 7 | #looping through an array 8 | for x in courses: 9 | print(x) 10 | 11 | #adding a new element into an array 12 | courses.append("java") 13 | print(courses) 14 | 15 | #removing an element 16 | courses.remove("Android") 17 | print(courses) -------------------------------------------------------------------------------- /assignment.py: -------------------------------------------------------------------------------- 1 | #a python program that returns the area of a trapezium 2 | # 1/2(a+b)*h 3 | 4 | a = float(input("what is the length of one side of the trapezium? ")) 5 | b = float(input("what is the length of the other side of the trapezium? ")) 6 | h = float(input("what is the height of the trapezium? ")) 7 | k = 0.5 8 | area = k*(a+b)*h 9 | print("the area of your trapezium is,",area) -------------------------------------------------------------------------------- /car.py: -------------------------------------------------------------------------------- 1 | class car: 2 | def __init__(self,color,yom): 3 | self.color = color 4 | self.yom = yom 5 | 6 | def drive(self): 7 | print("you drive",self.color,"car") 8 | 9 | car1 = car("black",2024) 10 | car2 = car ("grey",2023) 11 | car1.drive() -------------------------------------------------------------------------------- /classesobjects.py: -------------------------------------------------------------------------------- 1 | 2 | class student: 3 | #properties/variables/characteristics/attributes 4 | name = "tess" 5 | gender = "female" 6 | Age = 21 7 | 8 | #behavior/method 9 | def study(self): 10 | print("student is studying") 11 | 12 | mystudent = student() #this is creating a variable 13 | mystudent.study() 14 | print(mystudent.name) -------------------------------------------------------------------------------- /controlstatement.py: -------------------------------------------------------------------------------- 1 | temp =25 2 | if temp < 25 : 3 | print("tis too cold") 4 | else : 5 | print("warm") 6 | 7 | #program that returns the largest number 8 | num1 = 12 9 | num2 = 36 10 | num3 = 43 11 | 12 | if num1 > num2 and num1 > num3 : 13 | print(num1, "is the largest number") 14 | elif num2 > num1 and num2 > num3 : 15 | print(num2, "is the largest number") 16 | elif num3 > num1 and num3 > num2 : 17 | print(num3, "is the largest number") 18 | 19 | #program to check whether a number is even or odd 20 | number =0 21 | if number == 0: 22 | print(number,"is a neutral number") 23 | elif number % 2 == 0: 24 | print(number,"is an even number") 25 | else: 26 | print(number,"is an odd number") -------------------------------------------------------------------------------- /course.py: -------------------------------------------------------------------------------- 1 | import module, functions 2 | 3 | module.course("john","data science") 4 | functions.employee("jane",45,"director",450000) -------------------------------------------------------------------------------- /datatype.py: -------------------------------------------------------------------------------- 1 | 2 | number = 20 #int 3 | num = 34.67 #float 4 | greetings = "hello there" #str 5 | ispythoninteresting = True #boolean 6 | 7 | #Data structures 8 | 9 | cars = ["Honda","Porsche","Subaru"]#list 10 | fruits = ("Banana","Apple","Orange")#tuple 11 | countries = {"Kenya","Germany","Italy"}#set 12 | details = { 13 | "firstname": "Harrizon", 14 | "course": "MIT", 15 | "nationality":"Kenyan", 16 | "age" : 19 17 | }#dictionary -key-value pair 18 | 19 | print(number, type(number)) 20 | print(num) 21 | print(greetings) 22 | print(ispythoninteresting) 23 | 24 | print(cars) 25 | print(fruits) 26 | print(countries) 27 | print(details) 28 | print(details ["nationality"]) 29 | 30 | #determining the data type 31 | print(type(number)) 32 | print(type(num)) 33 | print(type(greetings)) 34 | print(type(ispythoninteresting)) 35 | print(type(countries)) 36 | 37 | #typecasting - converting one datatype to another 38 | print(float(number)) 39 | print(int(num)) -------------------------------------------------------------------------------- /encapsulation.py: -------------------------------------------------------------------------------- 1 | import random 2 | print("These are the rules for the game \n" 3 | "Rock vs Paper, Paper wins \n" + 4 | "Rock vs Scissors, Rock wins \n" + 5 | "Paper vs Scissors, Scissors wins") 6 | 7 | print("enter any number from the below \n"+ 8 | "1.Rock \n"+ 9 | "2.Paper \n"+ 10 | "3.Scissors \n") 11 | 12 | choice = int(input("Enter your choice: ")) 13 | if choice == 1: 14 | choice_name = 'Rock' 15 | elif choice == 2: 16 | choice_name = 'Paper' 17 | else: 18 | choice_name = 'Scissors' 19 | 20 | print("you chose,",choice_name) 21 | computers_choice = random.randint(1,3) 22 | if computers_choice == 1: 23 | computers_choice_name = 'Rock' 24 | elif computers_choice == 2: 25 | computers_choice_name = 'Paper' 26 | else: 27 | computers_choice_name = 'Scissors' 28 | 29 | print("the computer chose,",computers_choice_name) 30 | print('result is:',choice_name, 'vs', computers_choice_name) 31 | 32 | if choice == computers_choice: 33 | result = "DRAW" 34 | elif (choice == 1 and computers_choice == 2) or (computers_choice == 1 and choice == 2): 35 | result = 'Paper' 36 | elif (choice == 1 and computers_choice == 3) or (computers_choice == 1 and choice == 3): 37 | result = 'Rock' 38 | elif (choice == 2 and computers_choice == 3) or (computers_choice == 2 and choice == 3): 39 | result = 'Scissors' 40 | 41 | # Print the result 42 | if result == "DRAW": 43 | print("It's a tie!") 44 | elif result == choice_name: 45 | print("User wins!") 46 | else: 47 | print("Computer wins!") 48 | 49 | -------------------------------------------------------------------------------- /exceptions.py: -------------------------------------------------------------------------------- 1 | 2 | try : 3 | print(x) 4 | except: 5 | print("an error occurred") 6 | finally: 7 | print("success") 8 | 9 | try: 10 | num1 = 20 11 | num2 = 2 12 | print(num1 / num2) 13 | except: 14 | print("an error occurred") -------------------------------------------------------------------------------- /functions.py: -------------------------------------------------------------------------------- 1 | #built-in functions 2 | y =max(56, 75, 23, 18, 16) 3 | print("the maximum value is", y) 4 | 5 | x = min(45, 6, 56) 6 | print("the min value is",x) 7 | 8 | #user defined functions 9 | def name(): 10 | print("harry") 11 | name()#calling a function 12 | 13 | def product(): 14 | a =10 15 | b =20 16 | print(a*b) 17 | product() 18 | 19 | #parameter/variable and argument/value 20 | def sum(num1, num2): 21 | print(num1 + num2) 22 | sum(5,6 ) 23 | sum(10,20) 24 | 25 | def employee(name, age, position, salary): 26 | print(name,age,position,salary) 27 | employee("harrison",18,"CEO",560000) 28 | employee("Gedaliah",18,"managing director",560000) 29 | 30 | 31 | #a program to display student info 32 | #fullname, age, course, gender, nationality 33 | def student(name, age, course, gender, nationality): 34 | print(name,age,course,gender,nationality) 35 | student("harrison",18,"MIT","male","kenyan") 36 | student("Gedaliah",18,"MIT","male","kenyan") 37 | student("mary",18,"MIT","female","kenyan") 38 | student("ezra",18,"MIT","male","kenyan") 39 | student("mugaya",18,"MIT","female","kenyan") 40 | 41 | -------------------------------------------------------------------------------- /inheritance.py: -------------------------------------------------------------------------------- 1 | #parent class/ super class/ base class 2 | class animal: 3 | def speak(self): 4 | print("animal is speaking") 5 | 6 | 7 | #child class/ subclass/ derived class 8 | class cat(animal): 9 | def meow(self): 10 | print("cat is meowing") 11 | 12 | class dog(cat): 13 | def bark(self): 14 | print("cat is barking") 15 | 16 | 17 | a = animal() 18 | 19 | 20 | 21 | c = cat() 22 | c.speak() 23 | d = dog() -------------------------------------------------------------------------------- /introduction.py: -------------------------------------------------------------------------------- 1 | page = input("my name is harrizon, what is yours? ") 2 | print( "hello," + page + " nice to meet you") 3 | age = int(input("so, "+page + "how old are you?")) 4 | print(page + int(age) +"yrs old") 5 | #print is a method used to display an output 6 | 7 | -------------------------------------------------------------------------------- /loops.py: -------------------------------------------------------------------------------- 1 | #while loop 2 | 3 | #this is an increment 4 | number = 105 5 | while number <= 110 : 6 | print(number) 7 | number +=1 8 | 9 | #decrement 10 | num =30 11 | while num >= 20: 12 | print("number is ",num) 13 | num -=1 14 | 15 | #for loop 16 | for count in range(1,10): 17 | print(count) 18 | 19 | for x in range(20,30 ,3): 20 | print("value is",x) 21 | 22 | language = ["python","c++","java"] 23 | for lang in language: 24 | print(lang) -------------------------------------------------------------------------------- /mathmodule.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | x = math.sqrt(81) 4 | print(x) 5 | 6 | y = math.ceil(34.5) 7 | print(y) 8 | 9 | z = math.floor(34.5) 10 | print(z) -------------------------------------------------------------------------------- /module.py: -------------------------------------------------------------------------------- 1 | def course(name, mycourse): 2 | print(name, mycourse) 3 | 4 | course("harry","MIT") 5 | course("gedaliah","cybersecurity") -------------------------------------------------------------------------------- /oop1.py: -------------------------------------------------------------------------------- 1 | class person: 2 | def __init__(self,name,gender,age): 3 | self.name = name 4 | self.gender = gender 5 | 6 | def detail(self): 7 | print(self.name, "is a ",self.gender) 8 | 9 | 10 | teacher = person("joe","male",45) 11 | teacher.detail() 12 | 13 | accountant = person("mary","female",30) 14 | accountant.detail() 15 | print(teacher.name) 16 | print(accountant.name) -------------------------------------------------------------------------------- /operators.py: -------------------------------------------------------------------------------- 1 | #arithmetic operators 2 | num1 =10 3 | num2 =5 4 | 5 | print(num1+num2) 6 | print(num1-num2) 7 | print(num1*num2) 8 | print(num1/num2) 9 | print(num1%num2)#modulus - it returns the remainder after dividing the two values 10 | 11 | #assignmet operators 12 | x =20 13 | x +=2 14 | 15 | 16 | 17 | 18 | 19 | print(num1num2) 21 | print(num1<=num2) 22 | print(num1>=num2) 23 | print(num1==num2)#equal to 24 | print(num1!=num2)#not equal to 25 | print(x) 26 | 27 | #logical operators - and, or, not 28 | print(30<45 and 100>250) 29 | print(30<45 or 100>250) 30 | print(not(30<45 or 100>250)) 31 | 32 | 33 | -------------------------------------------------------------------------------- /polymorphism.py: -------------------------------------------------------------------------------- 1 | class shape: 2 | def draw(self): 3 | print("drawing a shape") 4 | 5 | 6 | class parallelogram: 7 | def draw(self): 8 | print("drawing a parallelogram") 9 | 10 | 11 | class rhombus: 12 | def draw(self): 13 | print("drawing a rhombus") 14 | 15 | 16 | 17 | sh = shape() 18 | sh.draw() 19 | p = parallelogram() 20 | r = rhombus() -------------------------------------------------------------------------------- /string.py: -------------------------------------------------------------------------------- 1 | from calendar import firstweekday 2 | 3 | from datatype import greetings 4 | 5 | text = "Hello world" 6 | course = "SOFTWARE DEVELOPMENT" 7 | greeting = "Hello there " 8 | firstname = "Harrizon" 9 | 10 | print(text) 11 | print(course) 12 | 13 | #accesing an element in a string 14 | print(text[0]) 15 | print(text[0:5]) 16 | print(text[2]) 17 | 18 | #determining size/length of a str 19 | print(len(text)) 20 | 21 | #modifying a str 22 | print(course.lower()) 23 | print(text.upper()) 24 | 25 | #str concatenation - joining str 26 | print(greeting+firstname) 27 | print(greeting + " " + firstname) 28 | 29 | -------------------------------------------------------------------------------- /useinputoutput.py: -------------------------------------------------------------------------------- 1 | firstname = input("Enter your first name: ") 2 | print("hey",firstname) 3 | 4 | age = int(input("what about your age? ")) 5 | if age >= 18: 6 | print("you are an adult",firstname) 7 | else: 8 | print("you are a child",firstname) 9 | 10 | -------------------------------------------------------------------------------- /variables.py: -------------------------------------------------------------------------------- 1 | lang = "python" 2 | print(lang,"is a web programming language") 3 | num1 = 2 4 | num2 = 3 5 | print("sum of",num1,"and",num2,"is",num1+num2 ) --------------------------------------------------------------------------------