Skip to content

Instantly share code, notes, and snippets.

@QuintD
QuintD / GuessNumGame.py
Created March 8, 2022 09:17
A number guess game
import random
random_number = random.randint(0, 20)
guess_number = input("enter your guess number: ")
guess_number = int(guess_number)
while random_number != guess_number:
if random_number > guess_number:
print("your guess is less than the random number")
else:
print("your guess is higher than the random number")
guess_number = input("enter your guess number")
@QuintD
QuintD / dicProb.py
Created March 8, 2022 09:20
Shows how you can use dictionary data structure in Python.
# to check for the number of occurrence of each items in a list, here is the way to go.
list = [2, 2, 3, 5, 5, 7, 7, 0, 2, 3, 1, 0, 5]
dic = {}
for x in list:
if x in dic:
count = dic[x]
else:
count = 0
dic[x] = count + 1
for key, value in dic.items():
@QuintD
QuintD / List.py
Last active March 8, 2022 09:24
this shows how best to use a list in python, with an example on how to check for the maximum number in a list.
my_food_item_list = ["Garri", "Peak milk", "Bournvita", "Cornflakes", "Biscuit", "Peak milk", "Milo", "Groundnut"]
first_item = my_food_item_list[0]
second_item = my_food_item_list[1]
fifth_item = my_food_item_list[4]
print(first_item)
print(second_item)
print(fifth_item)
# # for negative indexing
item = my_food_item_list[-3]
@QuintD
QuintD / setEx.py
Created March 8, 2022 09:26
this is an exercise with Set in python. To check the highest item in a set of numbers.
b_set = {5, 20, 70, 46, 50}
highestNum = 0
for item in b_set:
if item > highestNum:
highestNum = item
print("the item with the highest vale in", b_set, "is", highestNum)