index
int64
repo_name
string
branch_name
string
path
string
content
string
import_graph
string
35,131
derick-droid/pythonbasics
refs/heads/main
/list.py
# using while loops in list # verifying users prev_user = ["derrick", "okinda", "kibaso"] new_users = [] current_user = [] while prev_user: new_users = prev_user.pop() print(f"verifying: {new_users}") current_user.append(new_users) print("the following users have been confirmed:") for user in current_user:...
{"/module.py": ["/largest_number.py"]}
35,132
derick-droid/pythonbasics
refs/heads/main
/movie.py
# 7-5. Movie Tickets: A movie theater charges different ticket prices depending on # a person’s age. If a person is under the age of 3, the ticket is free; if they are # between 3 and 12, the ticket is $10; and if they are over age 12, the ticket is # $15. Write a loop in which you ask users their age, and then tell th...
{"/module.py": ["/largest_number.py"]}
35,133
derick-droid/pythonbasics
refs/heads/main
/diif_21.py
# Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21. # # diff21(19) → 2 # diff21(10) → 11 # diff21(21) → 0 def diff_21(n): if n <= 21: return abs(n - 21) else: return (abs(n - 21)) * 2
{"/module.py": ["/largest_number.py"]}
35,134
derick-droid/pythonbasics
refs/heads/main
/ifstatement.py
is_hot = False is_cold = False if is_hot: print("it is a hot day") print("drink a plenty of water") elif is_cold: print("it is a cold day ") print("wear warm clothes") else: print("it is a lovely day") print("enjoy your day") # IF STATEMENTS EXERCISE mark_price = 1000000 good_credit = False if g...
{"/module.py": ["/largest_number.py"]}
35,135
derick-droid/pythonbasics
refs/heads/main
/tuplecrash.py
# 4-13. Buffet: A buffet-style restaurant offers only five basic foods. Think of five # simple foods, and store them in a tuple. # • Use a for loop to print each food the restaurant offers. # • Try to modify one of the items, and make sure that Python rejects the # change. # • The restaurant changes its menu, replacing...
{"/module.py": ["/largest_number.py"]}
35,136
derick-droid/pythonbasics
refs/heads/main
/comparison.py
# >,>, >=,<=,==, != temperature = 30 if temperature >= 35: print("it is hot day ") else: print("it is a lovely day") #COMPARISON OPERATOR EXERSICE name = input("name: ") if len(name) < 3: # LEN FUNCTION COUNT NUMBER OF CHARACTERS ENTERED BY THE USER print("characters must be at least 3") elif len(name) > ...
{"/module.py": ["/largest_number.py"]}
35,137
derick-droid/pythonbasics
refs/heads/main
/rectangle.py
for row in range(4): for col in range(8): if (col == 0 or col == 7 ) or (row == 0 or row == 3): print("*", end=" ") else: print(end=" ") print()
{"/module.py": ["/largest_number.py"]}
35,138
derick-droid/pythonbasics
refs/heads/main
/functions.py
def pop (): """ description of greeting""" print("hello") print("come") pop() print("jaya") print() # passing information to a function def great_user(name): print(f"hello {name} ") great_user("john")
{"/module.py": ["/largest_number.py"]}
35,139
derick-droid/pythonbasics
refs/heads/main
/fronttimes.py
# Given a string and a non-negative int n, we'll say that the front of the string is the first 3 chars, or whatever is there if the string is less than length 3. Return n copies of the front; # # front_times('Chocolate', 2) → 'ChoCho' # front_times('Chocolate', 3) → 'ChoChoCho' # front_times('Abc', 3) → 'AbcAbcAbc' de...
{"/module.py": ["/largest_number.py"]}
35,140
derick-droid/pythonbasics
refs/heads/main
/main.py
# exceptions helps to limit codes from crushing try: age = int(input("age: ")) income = 20000 rate = income // age print(age) print(rate) except ValueError: print("invalid value") except ZeroDivisionError: print("invalid age value")
{"/module.py": ["/largest_number.py"]}
35,141
derick-droid/pythonbasics
refs/heads/main
/default.py
def describe_pet(animal_name, animal_type = "dog"): print(f"\n I have {animal_type}") print(f"my {animal_type} name is {animal_name}") describe_pet("willie")
{"/module.py": ["/largest_number.py"]}
35,142
derick-droid/pythonbasics
refs/heads/main
/optional.py
# optional arguments def user_names(first_name, last_name, middle_name = ""): if middle_name: full_name = first_name + " " + middle_name + " " + last_name + "." return full_name else: full_name = first_name + " " + last_name + "." return full_name musician = user_nam...
{"/module.py": ["/largest_number.py"]}
35,143
derick-droid/pythonbasics
refs/heads/main
/return.py
def get_formatted(first_name, last_name): full_name = (first_name + " " + last_name + ".") return full_name.title() musian = get_formatted("john", "timothy") print(musian)
{"/module.py": ["/largest_number.py"]}
35,144
derick-droid/pythonbasics
refs/heads/main
/dictionarycsdojo.py
naming = { "geogre": 24, "derrick": 23, "enock": 34, "jehova": 23 } for keys, values in naming.items(): print("keys") print(keys) print("values") print(values) print(" ")
{"/module.py": ["/largest_number.py"]}
35,145
derick-droid/pythonbasics
refs/heads/main
/nest2dic.py
# creating nested dictionary with for loop aliens = [] for alien_number in range (30): new_alien = { "color" : "green", "point" : 7, "speed" : "high" } aliens.append(new_alien) print(aliens) for alien in aliens[:5]: if alien["color"] == "green": alien["color"] == "red"...
{"/module.py": ["/largest_number.py"]}
35,146
derick-droid/pythonbasics
refs/heads/main
/files.py
# checking files in python open("employee.txt", "r") # to read the existing file open("employee.txt", "a") # to append information into a file employee = open("employee.txt", "r") # employee.close() # after opening a file we close the file print(employee.readable()) # this is to check if the file is readable prin...
{"/module.py": ["/largest_number.py"]}
35,147
derick-droid/pythonbasics
refs/heads/main
/keyword_argument.py
def welcoming_greet(first_name, last_name): print(f"hi {first_name} {last_name} ") print("welcome abroad ") print("hey new employee") welcoming_greet(first_name="john", last_name="monly") # keyword argument welcoming_greet("derrick", "okinda") # positional argument/ positional argument do come first before k...
{"/module.py": ["/largest_number.py"]}
35,148
derick-droid/pythonbasics
refs/heads/main
/exits.py
# 7-6. Three Exits: Write different versions of either Exercise 7-4 or Exercise 7-5 # that do each of the following at least once: # • Use an active variable to control how long the loop runs. # • Use a break statement to exit the loop when the user enters a 'quit' value. # active active = True while active: mes...
{"/module.py": ["/largest_number.py"]}
35,149
derick-droid/pythonbasics
refs/heads/main
/inputwhileloops.py
# prompt helps when one wants to display along message prompt = "If you tell us who you are, we can personalize the messages you see." prompt += "\nWhat is your first name? " name = input(prompt) print(name) print() # use int() input # determining the appropriaate height to ride a bicycle height = int(input("what i...
{"/module.py": ["/largest_number.py"]}
35,150
derick-droid/pythonbasics
refs/heads/main
/persona1.py
class Robots: def __init__(self, name, color, weight): self.name = name self.color = color self.weight = weight def introduce_yourself(self): print("my name is " + self.name) print("I am " + self.color) print("I weigh " + self.weight) class Persona(Robots): ...
{"/module.py": ["/largest_number.py"]}
35,151
derick-droid/pythonbasics
refs/heads/main
/arguments.py
# positional argument def my_pet (animal_type, animal_name): print(f"\nI have {animal_type} ") print(f"{animal_type} name is {animal_name} ") my_pet("cat", "pusss") # calling multiple functions my_pet("dog", "rex")
{"/module.py": ["/largest_number.py"]}
35,152
derick-droid/pythonbasics
refs/heads/main
/forlooop.py
names = ["paul", "derrick", "enock", "dave"] for name in names: print(name) # USING THE RANGE FUNCTIONS for items in range (100): # THE FUNCTION IS USED TO WIDE RANGE OF VALUES RATHER THAN CODING print(items) # USING RANGE FUNCTIONS TO OUTPUT SEQUENCE OF NUMBERS for items in range (2,10,2): print(items) #...
{"/module.py": ["/largest_number.py"]}
35,153
derick-droid/pythonbasics
refs/heads/main
/listcsdojo.py
a = [ 1, 2, 4, 6, 7, 8 ] a.append(34) print(a) # adding a list into yhe list a.append([1, 4, 5, 6, ]) print(a) # swapping within the list b = ["banana", "apple", "microsoft"] temp = b[0] b[0] = b[2] b[2] = temp print(b) # using another method b[1], b[2] = b[2], b[1] print(b)
{"/module.py": ["/largest_number.py"]}
35,154
derick-droid/pythonbasics
refs/heads/main
/functinscsdojo.py
# functions as collection of codes def function1(): print("this is s function ") print("thi is still within the function") print("this is outside the function") # using function as a mapping def function2(x, y): return x + y print("here we start ") function1() print(function2(3, 6))
{"/module.py": ["/largest_number.py"]}
35,155
derick-droid/pythonbasics
refs/heads/main
/randommss.py
import random value = random.random() # random numbers between 1 and 0 print(value) for i in range(3): print(random.randint(20,56)) # this gives random numbers between numbers specified members = ["derick", "john", "conf"] leader = random.choice(members) print(leader) # exercise choosing random numbers # dice ...
{"/module.py": ["/largest_number.py"]}
35,156
derick-droid/pythonbasics
refs/heads/main
/testdic.py
# Person: Use a dictionary to store information about a person you know. # Store their first name, last name, age, and the city in which they live. You # should have keys such as first_name , last_name , age , and city . Print each # piece of information stored in your dictionary. person = { "first_name" : "derric...
{"/module.py": ["/largest_number.py"]}
35,157
derick-droid/pythonbasics
refs/heads/main
/key argument.py
def my_pet(animal_name, animal_type): print(f"\n I have {animal_name}") print(f"{animal_name} is {animal_type}") my_pet(animal_name="cat", animal_type="jesse")
{"/module.py": ["/largest_number.py"]}
35,158
derick-droid/pythonbasics
refs/heads/main
/persona.py
class Robots: def __init__(self, name, color, weight): self.name = name self.color = color self.weight = weight def introduce_yourself(self): print("my name is " + self.name ) print("I am " + self.color ) print("I weigh " + self.weight) r1 = Robots("Tom", "bl...
{"/module.py": ["/largest_number.py"]}
35,159
derick-droid/pythonbasics
refs/heads/main
/whileloopcsdojo.py
# calculating total using while loops total = 0 j = 1 while j < 5: total += j j += 1 print(total) # adding elements in a list using while loop numbers = [5, 4, 3, 2, 1, -1, -2, -3, ] total2 = 0 i = 0 while i < len(numbers) and numbers[1] > 0: total2 += i i += 1 print(total2) # adding elements in a li...
{"/module.py": ["/largest_number.py"]}
35,160
derick-droid/pythonbasics
refs/heads/main
/frontback.py
# Given a string, return a new string where the first and last chars have been exchanged. # # front_back('code') → 'eodc' # front_back('a') → 'a' # front_back('ab') → 'ba' def front_back(str): front = str[0] back = str[-1] mid = str[1:-1] if len(str) <= 1: print(str) ...
{"/module.py": ["/largest_number.py"]}
35,161
derick-droid/pythonbasics
refs/heads/main
/funexer.py
# 8-1. Message: Write a function called display_message() that prints one sen- # tence telling everyone what you are learning about in this chapter. Call the # function, and make sure the message displays correctly. def display_message (): print("we are learning how to use finctions in this chapter") display_mess...
{"/module.py": ["/largest_number.py"]}
35,162
derick-droid/pythonbasics
refs/heads/main
/pyramid.py
num = int(input("enter number of rows : ")) for i in range(0, num): for j in range(i, num-1): print(end=" ") for j in range(i+1): print("*", end=" ") print()
{"/module.py": ["/largest_number.py"]}
35,163
derick-droid/pythonbasics
refs/heads/main
/dicdic.py
# dictionary inside dictionary user_name = { "derrick" : { "first-name" : "okinda", "last-name" : "kibaso", "location" : "Thika town" }, "ojwang": { "first-name": "derrick", "last-name": "ojwang'", "location": "kiang'ombe" } } for user, user_info in user_n...
{"/module.py": ["/largest_number.py"]}
35,164
derick-droid/pythonbasics
refs/heads/main
/classes.py
# creating a class for a dog class Dog: def __init__(self, name, age): self.name = name self.age = age def sit(self): print(f"the dog {self.name} is now sitting") def rollover(self): print(f"{self.name} is rolling") # creating instance of a class my_dog = Dog("rex", 23)...
{"/module.py": ["/largest_number.py"]}
35,165
derick-droid/pythonbasics
refs/heads/main
/simpledic.py
alien_0 = { "colour" : "green", "points" : 5 } print(alien_0["colour"]) print(alien_0["points"]) new_alien = alien_0["points"] print(f"your new point is {new_alien} that is very good") print() # adding values in dictionary print(alien_0) alien_0["x_coordinate"] = 0 alien_0["y_coordinate"] = 25 alien_0["size"] ...
{"/module.py": ["/largest_number.py"]}
35,166
derick-droid/pythonbasics
refs/heads/main
/2dlist.py
# 2D LISTS ARE EXAMPLE OF MATRICES matrix = [ [1, 2, 3], [3, 6, 8], [6, 7, 9] ] matrix[0] # INDEX 0 OF THE MATRIX REPRESENTS LISTS AVAILABLE IN THE LIST print(matrix) print(matrix[0] [1]) # ACCESSING VALUE IN THE INNER LIST (matrix[0] [1]) print(matrix) # ITERATING OVER A 2D LIST matrix = [ [1, 2, ...
{"/module.py": ["/largest_number.py"]}
35,167
derick-droid/pythonbasics
refs/heads/main
/iflsttry.py
# 5-8. Hello Admin: Make a list of five or more usernames, including the name # 'admin' . Imagine you are writing code that will print a greeting to each user # after they log in to a website. Loop through the list, and print a greeting to # each user: # • If the username is 'admin' , print a special greeting, such as ...
{"/module.py": ["/largest_number.py"]}
35,168
derick-droid/pythonbasics
refs/heads/main
/nestdic.py
aliens_0 = { "color": "green", "point": 6 } alien_1 = { "color": "yellow", "point": 3 } alien_2 = { "color": "blue", "point": 4 } aliens = [alien_2, alien_1, aliens_0] for alien in aliens: print(alien) print() # using range function alien1 = [] for alien_number in range(30): new_alie...
{"/module.py": ["/largest_number.py"]}
35,169
derick-droid/pythonbasics
refs/heads/main
/listsmethod.py
# METHODS WE CAN BE USED TO OPERATE ON OUR LISTS numbers = [5, 2, 6, 3, 2, 4, 8] numbers.append(10) # THE APPEND FUNCTION IS USED TO ADD ITEMS IN THE LIST print(numbers) numbers.insert(0,23) # THE INSERT METHOD IS USED TO ADD ITEMS IN THE LIST AT ANY INDEX print(numbers) numbers.remove(5) # THE REMOVE FUNCTION IS U...
{"/module.py": ["/largest_number.py"]}
35,170
derick-droid/pythonbasics
refs/heads/main
/sets.py
# sets sorting of data is not considered # sets don't allow any duplication of data # sets can be used to check if two sets share common data this can be by using the intersection function course = {"maths", "Compsci", "chemistry", "history", "statistics", "Compsci"} print(course) print() art_course = {"maths", "Com...
{"/module.py": ["/largest_number.py"]}
35,171
derick-droid/pythonbasics
refs/heads/main
/functionbmiclculator.py
def bmi_calculator(name, height, weight ): bmi = weight / (height ** 2) print("your bmi is: ", bmi) if bmi < 25: print("hello " + name + " you have a normal bmi. ") else: print("hello " + name + " you have a normal bmi.") return bmi bmi1 = bmi_calculator("derrick okinda", 23, 45) b...
{"/module.py": ["/largest_number.py"]}
35,172
derick-droid/pythonbasics
refs/heads/main
/numbers.py
print(2+3) # the addition operation in python print(4_4) # the subtraction operation in python print(3*6) # the multiplication operation in python print(10 % 3) # the modulus operation which gives the remainder as answer print(10 / 3) # this is a divisional operation print(10//3) # this gives a whole answer and i...
{"/module.py": ["/largest_number.py"]}
35,173
derick-droid/pythonbasics
refs/heads/main
/upside_reightangle.py
num = int(input("enter row: ")) for i in range(num, 0 , -1): for j in range(0, num-1): print(end="") for j in range(0,i): print("*", end=" ") print()
{"/module.py": ["/largest_number.py"]}
35,174
derick-droid/pythonbasics
refs/heads/main
/reusable_function.py
# USABLE FUNCTION HELPS TO AVOID CODING MORE CODES def welcoming_greet(name): print(f"hi {name} there") name = input("what is your name: ") print(name) welcoming_greet(name)
{"/module.py": ["/largest_number.py"]}
35,175
derick-droid/pythonbasics
refs/heads/main
/module.py
# from largest_number import largest_number # biggest_number = largest_number(numbers) # print(biggest_number) from largest_number import find_biggest_number numbers = [2, 3, 73, 83, 27, 7, ] biggest_number = find_biggest_number(numbers) print(biggest_number)
{"/module.py": ["/largest_number.py"]}
35,176
derick-droid/pythonbasics
refs/heads/main
/dictionarycorey.py
students = { "name ": "derick", "age ": 25, "course ": ["maths", "programming"] } print(students["name "]) print(students["age "]) print(students["course "]) print() # accessing values which are not in the dictionary without getting an error print(students.get("phone", "not found")) # adding values into ...
{"/module.py": ["/largest_number.py"]}
35,177
derick-droid/pythonbasics
refs/heads/main
/strings.py
print("GIRAFFE") print("Giraffe\nAcademy") # the \n is used to create new tab between the strings print("Giraffe\"academy") # the escalation inserts quotation in between the words phrase = "giraffe academy" # storing string in a variable print(phrase) # contenation of a string print(phrase + " is cool") # using t...
{"/module.py": ["/largest_number.py"]}
35,178
derick-droid/pythonbasics
refs/heads/main
/condtion.py
language = "python" if language == "java": print("The language is java") elif language == "python": print("language is python") else: print("there is no match at all") # using the booleans # and user = "admin page" logged_in = False if user and logged_in == True: print("welcome admin") # or if us...
{"/module.py": ["/largest_number.py"]}
35,179
derick-droid/pythonbasics
refs/heads/main
/exerinput.py
# 7-1. Rental Car: Write a program that asks the user what kind of rental car they # would like. Print a message about that car, such as “Let me see if I can find you # a Subaru.” car = input("what car do you want: ") print(f"let me see if I can get {car}") print() # 7-2. Restaurant Seating: Write a program that asks ...
{"/module.py": ["/largest_number.py"]}
35,180
derick-droid/pythonbasics
refs/heads/main
/listcorey.py
courses = ["history", "geography", "maths", "compsci"] # using for loop to access both index and items in the list for index, course in enumerate(courses): # we use the enumerate function print(index, course) print() # if we want to start from index 1 we add start statement for index, course in enumerate(cours...
{"/module.py": ["/largest_number.py"]}
35,181
derick-droid/pythonbasics
refs/heads/main
/ifstatementcsdojo.py
a = 1 b = 2 if a < b: print("a is less than b") else: print("a is greater than b") # more of if statements f = 18 j = 4 if f > j + 10: print("f is greater than j by 10") elif j > f +10: print("j is greater than f by 10") else: print("none of the above comparison") # more of if statement h = 18 z...
{"/module.py": ["/largest_number.py"]}
35,182
derick-droid/pythonbasics
refs/heads/main
/largest_number.py
# def largest_number(numbers): # biggest_number = numbers[0] # for number in numbers: # if number > biggest_number: # biggest_number = number # return biggest_number # numbers = [2, 3, 73, 83, 27, 7, ] def find_biggest_number(numbers): biggest_number = numbers[0] for numb...
{"/module.py": ["/largest_number.py"]}
35,183
derick-droid/pythonbasics
refs/heads/main
/flags.py
prompt = "\nenter your message here please:" prompt += "\n enter message:" # using flags in while loops active = True while active: message = input(prompt) if message.lower() == "quit": active = False else: print(message)
{"/module.py": ["/largest_number.py"]}
35,184
derick-droid/pythonbasics
refs/heads/main
/pizza.py
# 7-4. Pizza Toppings: Write a loop that prompts the user to enter a series of # pizza toppings until they enter a 'quit' value. As they enter each topping, # print a message saying you’ll add that topping to their pizza. # exercise on while loops basics prompt = "\n enter a serie of pizza toppings " prompt += "\n ente...
{"/module.py": ["/largest_number.py"]}
35,185
derick-droid/pythonbasics
refs/heads/main
/nestedloops.py
for x in range (5): for y in range (4): print(f"{x}, {y} ") #EXERCISE OF NESTED LOOPS numbers = [5, 2, 5, 2, 2 ] for number in numbers: # BUT NO NESTED LOOPS USED print("*" * number) # USING NESTED LOOPS numbers = [5, 2, 5, 2, 2] for number in numbers: output = "" x_counts = output for i...
{"/module.py": ["/largest_number.py"]}
35,186
derick-droid/pythonbasics
refs/heads/main
/lists.py
# BASIC IN LST name = ["derrick", "john", "mosh", "sarah"] print(name) # USING INDEX TO RETRIEVE VALUE FROM A LIST name = ["derrick", "john", "mosh", "sarah"] print(name[0]) # PRINTING VALUE AT INDEX ZERO print(name[2:]) # PRINTING VALUE FROM INDEX 2 TO THE LAST INDEX IN THE LIST print(name[:]) # PRINTS THE WHOLE ...
{"/module.py": ["/largest_number.py"]}
35,187
derick-droid/pythonbasics
refs/heads/main
/loops[lst].py
# looping over a list of an item magicians = ["alice", "nana", "caroh"] for magician in magicians: print(f"{magician.title()} you did a good work") print("I cannot wait to see your next trick \n") # exercise # 4-1. Pizzas: Think of at least three kinds of your favorite pizza. Store these # pizza names in a l...
{"/module.py": ["/largest_number.py"]}
35,188
derick-droid/pythonbasics
refs/heads/main
/files and directories.py
from pathlib import Path path = Path() for file in path.glob("*.py"): print(file) # Absolute path # relative path path = Path("ecommerce") print(path.exists()) # exists method checks the presence of a directory # print(path.mkdir()) # to make a directory # print(path.rmdir()) # this is to remove a directory # gl...
{"/module.py": ["/largest_number.py"]}
35,189
derick-droid/pythonbasics
refs/heads/main
/parameter.py
def welcoming_greet(first_name, last_name): print(f"hi {first_name} {last_name} ") print("welcome abroad ") print("hey new employee") welcoming_greet("john", "monly") welcoming_greet("derrick", "okinda") print("thanking fo accepting our call")
{"/module.py": ["/largest_number.py"]}
35,190
derick-droid/pythonbasics
refs/heads/main
/listfunctions.py
lucky_numbers = [1, 2, 3, 4, 5, 6, 7] friends = ["derrick", "jim", "jim", "trump", "majani" ] friends.extend(lucky_numbers) # to add another list on another list print(friends) print(friends.count("jim")) # to count repetitive objects in a list
{"/module.py": ["/largest_number.py"]}
35,191
derick-droid/pythonbasics
refs/heads/main
/pastrami.py
# 7-9. No Pastrami: Using the list sandwich_orders from Exercise 7-8, make sure # the sandwich 'pastrami' appears in the list at least three times. Add code # near the beginning of your program to print a message saying the deli has # run out of pastrami, and then use a while loop to remove all occurrences of # 'pastra...
{"/module.py": ["/largest_number.py"]}
35,192
derick-droid/pythonbasics
refs/heads/main
/logicaloperator.py
has_high_income = True has_good_credit = True has_criminal_record = False if has_high_income and has_good_credit: print("eligible for loan") elif has_good_credit or not has_criminal_record: print("eligible for loan") elif has_good_credit and has_high_income and not has_criminal_record: print("eligible for ...
{"/module.py": ["/largest_number.py"]}
35,193
derick-droid/pythonbasics
refs/heads/main
/listcomprehension.py
# doubling elements in a list a = [1, 34, 6, 54, 344, 4555, 4] b = [] for elements in a: multiple = elements * 2 b.append(multiple) print(b) # list comprehension b = [elements * 2 for elements in a] print(b)
{"/module.py": ["/largest_number.py"]}
35,194
derick-droid/pythonbasics
refs/heads/main
/return_statements.py
def square(number): return number * number # it returns the value of a function to the user print(square(3))
{"/module.py": ["/largest_number.py"]}
35,195
derick-droid/pythonbasics
refs/heads/main
/lstnumbers.py
# 4-3. Counting to Twenty: Use a for loop to print the numbers from 1 to 20, for i in range(1, 21): print(i) # 4-4. One Million: Make a list of the numbers from one to one million, and then # use a for loop to print the numbers. (If the output is taking too long, stop it by # pressing ctrl -C or by closing the ou...
{"/module.py": ["/largest_number.py"]}
35,196
derick-droid/pythonbasics
refs/heads/main
/deli.py
# 7-8. Deli: Make a list called sandwich_orders and fill it with the names of vari- # ous sandwiches. Then make an empty list called finished_sandwiches . Loop # through the list of sandwich orders and print a message for each order, such # as I made your tuna sandwich. As each sandwich is made, move it to the list # o...
{"/module.py": ["/largest_number.py"]}
35,197
derick-droid/pythonbasics
refs/heads/main
/listdic.py
# stores information of pizza being ordered pizza = { "crust" : "thirst", "topping" : ["mushroom", "extra cheese"] } # summary of the order print("Your ordered pizza " + pizza["crust"] + "-crust pizza has the following toppings: ") for item in pizza["topping"]: print(item) # more examples students = { ...
{"/module.py": ["/largest_number.py"]}
35,198
derick-droid/pythonbasics
refs/heads/main
/stringsploison.py
# Given a non-empty string like "Code" return a string like "CCoCodCode". # # string_splosion('Code') → 'CCoCodCode' # string_splosion('abc') → 'aababc' # string_splosion('ab') → 'aab' def string_splosion(str): result = "" for itmes in str: if len(str) <= 1: print(str) elif len(str)...
{"/module.py": ["/largest_number.py"]}
35,199
derick-droid/pythonbasics
refs/heads/main
/exponent functions.py
def large_number(base_number, power_number): result = 1 for index in range(power_number): result = result * base_number return result print(large_number(3, 2))
{"/module.py": ["/largest_number.py"]}
35,200
derick-droid/pythonbasics
refs/heads/main
/dictionary.py
# returning dictionary in functionn def user_dictionary (first_name, last_name): full = { "first_name" : first_name, "last_name" : last_name } return full musician = user_dictionary("ford", "dancan") print(musician) # using optinal values in dictionary def dev_person(occupation, age, ...
{"/module.py": ["/largest_number.py"]}
35,201
derick-droid/pythonbasics
refs/heads/main
/triangle pattern.py
row = int(input("enter row: ")) column = int(input("enter column: ")) for i in range(row, column): print("*" * i)
{"/module.py": ["/largest_number.py"]}
35,202
derick-droid/pythonbasics
refs/heads/main
/forlooptechnique.py
for i in range(1, 10): print(i+1, "-----derrick") print() for i in range(10): print("derrick") print() for i in range(3, 7): print(i, "---derrick") print() for i in range(5, 2, -1): print(i, "---derrick")
{"/module.py": ["/largest_number.py"]}
35,203
derick-droid/pythonbasics
refs/heads/main
/continue.py
# using continue in while loops .continue is used to tell python to ignore the code and move the beginning of the loop current_number = 0 while current_number < 10: current_number += 1 if current_number % 2 == 0: continue else: print(current_number)
{"/module.py": ["/largest_number.py"]}
35,204
derick-droid/pythonbasics
refs/heads/main
/stringbits.py
# Given a string, return a new string made of every other char starting with the first, so "Hello" yields "Hlo". # # string_bits('Hello') → 'Hlo' # string_bits('Hi') → 'H' # string_bits('Heeololeo') → 'Hello' # def string_bits(str): # for items in str: if len(str) == 1: print(str[0]) eli...
{"/module.py": ["/largest_number.py"]}
35,205
derick-droid/pythonbasics
refs/heads/main
/ifcrash.py
# 5-3. Alien Colors #1: Imagine an alien was just shot down in a game. Create a # variable called alien_color and assign it a value of 'green' , 'yellow' , or 'red' . # • Write an if statement to test whether the alien’s color is green. If it is, print # a message that the player just earned 5 points. # • Write one ver...
{"/module.py": ["/largest_number.py"]}
35,206
derick-droid/pythonbasics
refs/heads/main
/arraycounts.py
# Given an array of ints, return the number of 9's in the array. # # array_count9([1, 2, 9]) → 1 # array_count9([1, 9, 9]) → 2 # array_count9([1, 9, 9, 3, 9]) → 3 def array_count9(nums): count = 0 # Standard loop to look at each value for num in nums: if num == 9: count = count + 1 print(count) pop =...
{"/module.py": ["/largest_number.py"]}
35,207
derick-droid/pythonbasics
refs/heads/main
/slicelst.py
# 4-10. Slices: Using one of the programs you wrote in this chapter, add several # lines to the end of the program that do the following: # • Print the message, The first three items in the list are:. Then use a slice to # print the first three items from that program’s list. # • Print the message, Three items from the...
{"/module.py": ["/largest_number.py"]}
35,208
derick-droid/pythonbasics
refs/heads/main
/tuples.py
# TUPLES ARE SIMILAR WITH LIST EXCEPT TUPLES CANNOT BE MODIFIED (THEY ARE IMMUTABLE) # TUPLE A(LSO PARENTHESIS INSTEAD OF SQUARE BRACKETS numbers = (1, 3, 4) print(numbers) print(numbers.count(4)) # THE COUNT METHOD IS USED TO COUNT ITEMS IN A TUPLE print(numbers.index(4)) # THE INDEX METHOD IS USED TO SHOW THE ...
{"/module.py": ["/largest_number.py"]}
35,209
derick-droid/pythonbasics
refs/heads/main
/constructor.py
# constructor is the function being called at the time of creating objects class Point: # constructor def __init__(self, x, y): self.x = x self.y = y def move(self): print("move") def draw(self): print("draw") point = Point(10, 37) print(point.y) print(point.x) # EX...
{"/module.py": ["/largest_number.py"]}
35,210
derick-droid/pythonbasics
refs/heads/main
/diamondshape.py
num = int(input("enter row: ")) num1 = int(input("enter row1: ")) # upright pyramid code for i in range(0, num): for j in range(0, num-i-1): print(end=" ") for j in range(0, i+1): print("*", end=" ") print() # combining the codes to form a diamond shape # inverse pyramid code for i in ran...
{"/module.py": ["/largest_number.py"]}
35,211
derick-droid/pythonbasics
refs/heads/main
/bools.py
# showing how to use data type in python def are_you_sad(is_raining, has_umbrella): if is_raining and not has_umbrella: print(True) else: print(False) are_you_sad(True, False) are_you_sad(True, True) # more exercise def c_greater_than_d_plus_e(c, d, e): # c= 48 # d = 3 # e = 8 ...
{"/module.py": ["/largest_number.py"]}
35,212
derick-droid/pythonbasics
refs/heads/main
/loopsdic.py
# Looping Through All Key-Value Pairs user_0 = { "user_name" : "arridez", "first_name" : "derrick", "last_name" : "beatrice", } for key, value in user_0.items(): print("key: \n" + key) print("value: \n" + value) print() # Looping Through All the Keys in a Dictionary favorite_languages = { ...
{"/module.py": ["/largest_number.py"]}
35,217
Veldrovive/alpha-zero-test
refs/heads/main
/arena.py
import logging import numpy as np from tqdm import tqdm from gameV2 import Gomaku from tree_search import TreeSearch log = logging.getLogger(__name__) class Arena: def __init__(self, player1: TreeSearch, player2: TreeSearch, game: Gomaku, verbose=False): self.player1 = player1 self.player2 = play...
{"/arena.py": ["/gameV2.py", "/tree_search.py"], "/tree_search.py": ["/gameV2.py", "/agent.py"], "/agent.py": ["/gameV2.py"], "/trainer.py": ["/gameV2.py", "/agent.py", "/tree_search.py", "/arena.py"], "/main.py": ["/gameV2.py", "/agent.py", "/trainer.py"]}
35,218
Veldrovive/alpha-zero-test
refs/heads/main
/tree_search.py
import logging import numpy as np from gameV2 import Gomaku from agent import Agent log = logging.getLogger(__name__) EPS = 1e-8 class TreeSearch: """ Handles monte carlo search tree operations """ def __init__(self, game: Gomaku, agent: Agent, args): self.game = game self.agent = a...
{"/arena.py": ["/gameV2.py", "/tree_search.py"], "/tree_search.py": ["/gameV2.py", "/agent.py"], "/agent.py": ["/gameV2.py"], "/trainer.py": ["/gameV2.py", "/agent.py", "/tree_search.py", "/arena.py"], "/main.py": ["/gameV2.py", "/agent.py", "/trainer.py"]}
35,219
Veldrovive/alpha-zero-test
refs/heads/main
/agent.py
import logging import os import torch from torch import optim from tqdm import tqdm import numpy as np from time import time from agent_net import Network from gameV2 import Gomaku log = logging.getLogger(__name__) args = { 'lr': 0.001, 'dropout': 0.3, 'epochs': 10, 'batch_size': 64, 'cuda': torc...
{"/arena.py": ["/gameV2.py", "/tree_search.py"], "/tree_search.py": ["/gameV2.py", "/agent.py"], "/agent.py": ["/gameV2.py"], "/trainer.py": ["/gameV2.py", "/agent.py", "/tree_search.py", "/arena.py"], "/main.py": ["/gameV2.py", "/agent.py", "/trainer.py"]}
35,220
Veldrovive/alpha-zero-test
refs/heads/main
/trainer.py
import logging import numpy as np from collections import deque from tqdm import tqdm from pickle import Pickler, Unpickler import os from gameV2 import Gomaku from agent import Agent from tree_search import TreeSearch from arena import Arena log = logging.getLogger(__name__) class Trainer: def __init__(self, ga...
{"/arena.py": ["/gameV2.py", "/tree_search.py"], "/tree_search.py": ["/gameV2.py", "/agent.py"], "/agent.py": ["/gameV2.py"], "/trainer.py": ["/gameV2.py", "/agent.py", "/tree_search.py", "/arena.py"], "/main.py": ["/gameV2.py", "/agent.py", "/trainer.py"]}
35,221
Veldrovive/alpha-zero-test
refs/heads/main
/game.py
from typing import List import numpy as np class Gomaku: content = { -1: "b", 0: " ", 1: "w" } inverse_content = { "b": -1, " ": 0, "1": 1 } @staticmethod def from_string_array(board: List[List[str]]): size = len(board) game = G...
{"/arena.py": ["/gameV2.py", "/tree_search.py"], "/tree_search.py": ["/gameV2.py", "/agent.py"], "/agent.py": ["/gameV2.py"], "/trainer.py": ["/gameV2.py", "/agent.py", "/tree_search.py", "/arena.py"], "/main.py": ["/gameV2.py", "/agent.py", "/trainer.py"]}
35,222
Veldrovive/alpha-zero-test
refs/heads/main
/main.py
import logging import torch import numpy as np import random import coloredlogs from gameV2 import Gomaku from agent import Agent from trainer import Trainer log = logging.getLogger(__name__) coloredlogs.install(level='INFO') # Change this to DEBUG to see more info or INFO to see less. args = { 'numIters': 100...
{"/arena.py": ["/gameV2.py", "/tree_search.py"], "/tree_search.py": ["/gameV2.py", "/agent.py"], "/agent.py": ["/gameV2.py"], "/trainer.py": ["/gameV2.py", "/agent.py", "/tree_search.py", "/arena.py"], "/main.py": ["/gameV2.py", "/agent.py", "/trainer.py"]}
35,223
Veldrovive/alpha-zero-test
refs/heads/main
/gameV2.py
import logging from typing import List, Tuple, Optional import numpy as np log = logging.getLogger(__name__) class Gomaku: content = { -1: "b", 0: "-", 1: "w" } inverse_content = { "b": -1, "-": 0, "1": 1 } def from_string_array(self, board_seed: ...
{"/arena.py": ["/gameV2.py", "/tree_search.py"], "/tree_search.py": ["/gameV2.py", "/agent.py"], "/agent.py": ["/gameV2.py"], "/trainer.py": ["/gameV2.py", "/agent.py", "/tree_search.py", "/arena.py"], "/main.py": ["/gameV2.py", "/agent.py", "/trainer.py"]}
35,228
yusing/RSS-Scrapper
refs/heads/master
/scrap.py
import asyncio import concurrent.futures import threading import warnings from asyncio.runners import run from datetime import datetime from textwrap import wrap from time import sleep from urllib.parse import urlparse import mysql.connector import newspaper import requests from bs4 import BeautifulSoup from bs4.eleme...
{"/query.py": ["/scrap.py"]}
35,229
yusing/RSS-Scrapper
refs/heads/master
/query.py
import mysql.connector import sys import webbrowser from scrap import fetch_news from hanziconv import HanziConv if len(sys.argv) == 1: command = 'help' else: command = sys.argv[1] args = sys.argv[2:] news_db = mysql.connector.connect( host='localhost', user='root', database='news' ) cursor = news_...
{"/query.py": ["/scrap.py"]}
35,257
aimerou/rfid-restaurant-app
refs/heads/main
/models.py
from pymongo import MongoClient class Carte: """ Modèle Carte. Pour effectuer les différentes transactions avec la base de données. """ client = MongoClient("mongodb+srv://ali:ali221@cluster0.xie2q.mongodb.net/restaudb?retryWrites=true&w=majority") db = client.restaudb collection = db.carte ...
{"/register_student.py": ["/get_uid.py", "/models.py"], "/solde_management.py": ["/get_uid.py", "/leds_management.py", "/models.py"]}
35,258
aimerou/rfid-restaurant-app
refs/heads/main
/get_uid.py
import RPi.GPIO as GPIO #Importe la bibliothèque pour contrôler les GPIOs from pirc522 import RFID import time GPIO.setmode(GPIO.BOARD) #Définit le mode de numérotation (Board) GPIO.setwarnings(False) #On désactive les messages d'alerte rc522 = RFID() #On instancie la lib def get_uid(): """ Fonction pour lir...
{"/register_student.py": ["/get_uid.py", "/models.py"], "/solde_management.py": ["/get_uid.py", "/leds_management.py", "/models.py"]}
35,259
aimerou/rfid-restaurant-app
refs/heads/main
/leds_management.py
#!/usr/bin/env python3.5 #-- coding: utf-8 -- import RPi.GPIO as GPIO #Importe la bibliothèque pour contrôler les GPIOs from pirc522 import RFID import time GPIO.setmode(GPIO.BOARD) #Définit le mode de numérotation (Board) GPIO.setwarnings(False) #On désactive les messages d'alerte LED_RED = 3 #Définit le numéro du...
{"/register_student.py": ["/get_uid.py", "/models.py"], "/solde_management.py": ["/get_uid.py", "/leds_management.py", "/models.py"]}
35,260
aimerou/rfid-restaurant-app
refs/heads/main
/register_student.py
import time from get_uid import get_uid from models import Carte from afficher_etudiant import afficher_etudiant, etudiant_existe, afficher_liste_etudiants def register_student(): """ Fonction pour enregistrer un nouvel étudiant au niveau de la base de données. """ i = 0 while i < 2: affic...
{"/register_student.py": ["/get_uid.py", "/models.py"], "/solde_management.py": ["/get_uid.py", "/leds_management.py", "/models.py"]}
35,261
aimerou/rfid-restaurant-app
refs/heads/main
/solde_management.py
from get_uid import get_uid from leds_management import * from models import Carte from afficher_etudiant import afficher_etudiant SOLDE_PETIT_DEJ = 50 SOLDE_REPAS = 100 def get_student_by_uid(uid): """ C'est une fonction pour avoir l'étudiant correspondant à l'uid de la carte """ for student in TEST...
{"/register_student.py": ["/get_uid.py", "/models.py"], "/solde_management.py": ["/get_uid.py", "/leds_management.py", "/models.py"]}
35,283
jGaboardi/watermark
refs/heads/master
/watermark/watermark.py
# -*- coding: utf-8 -*- """ Function to print date/time stamps and various system information. Authors: Sebastian Raschka <sebastianraschka.com>, Tymoteusz Wołodźko License: BSD 3 clause """ from __future__ import absolute_import import datetime import importlib import os import platform import subprocess import tim...
{"/watermark/watermark.py": ["/watermark/version.py"], "/watermark/magic.py": ["/watermark/__init__.py"], "/watermark/tests/test_watermark.py": ["/watermark/__init__.py"], "/watermark/__init__.py": ["/watermark/version.py", "/watermark/magic.py", "/watermark/watermark.py"], "/watermark/tests/test_watermark_gpu.py": ["/...
35,284
jGaboardi/watermark
refs/heads/master
/watermark/version.py
try: import importlib.metadata as importlib_metadata except ImportError: # Running on pre-3.8 Python; use importlib-metadata package import importlib_metadata try: __version__ = importlib_metadata.version("watermark") except Exception: __version__ = "unknown"
{"/watermark/watermark.py": ["/watermark/version.py"], "/watermark/magic.py": ["/watermark/__init__.py"], "/watermark/tests/test_watermark.py": ["/watermark/__init__.py"], "/watermark/__init__.py": ["/watermark/version.py", "/watermark/magic.py", "/watermark/watermark.py"], "/watermark/tests/test_watermark_gpu.py": ["/...
35,285
jGaboardi/watermark
refs/heads/master
/setup.py
# Sebastian Raschka 2014-2022 # IPython magic function to print date/time stamps and # various system information. # Author: Sebastian Raschka <sebastianraschka.com> # # License: BSD 3 clause from os.path import dirname, join, realpath from textwrap import dedent from setuptools import find_packages, setup PROJECT_...
{"/watermark/watermark.py": ["/watermark/version.py"], "/watermark/magic.py": ["/watermark/__init__.py"], "/watermark/tests/test_watermark.py": ["/watermark/__init__.py"], "/watermark/__init__.py": ["/watermark/version.py", "/watermark/magic.py", "/watermark/watermark.py"], "/watermark/tests/test_watermark_gpu.py": ["/...
35,286
jGaboardi/watermark
refs/heads/master
/watermark/magic.py
# -*- coding: utf-8 -*- """ IPython magic function to print date/time stamps and various system information. Author: Sebastian Raschka <sebastianraschka.com> License: BSD 3 clause """ from IPython.core.magic import Magics from IPython.core.magic import magics_class from IPython.core.magic import line_magic from IPytho...
{"/watermark/watermark.py": ["/watermark/version.py"], "/watermark/magic.py": ["/watermark/__init__.py"], "/watermark/tests/test_watermark.py": ["/watermark/__init__.py"], "/watermark/__init__.py": ["/watermark/version.py", "/watermark/magic.py", "/watermark/watermark.py"], "/watermark/tests/test_watermark_gpu.py": ["/...