diff --git a/al.py b/al.py new file mode 100644 index 0000000..d333925 --- /dev/null +++ b/al.py @@ -0,0 +1,25 @@ +import random + +HTH = 0 +HTT = 0 +myList = [] +i = 0 +numberOfTosses = 1000000 + +while i < numberOfTosses: + myList.append(random.randint(0,1)) + i += 1 + +for i in range (len(myList)): + + if i+2 >= len(myList): + break + + if myList[i] == 1 and myList[i+1] == 0 and myList[i+2] == 1: + HTH +=1 + + if myList[i] == 1 and myList[i+1] == 0 and myList[i+2] == 0: + HTT +=1 + +print ('HTT :' ,numberOfTosses, HTT, numberOfTosses/HTT) +print ('HTH :' ,numberOfTosses, HTH, numberOfTosses/HTH) \ No newline at end of file diff --git a/bugo.gif b/bugo.gif new file mode 100644 index 0000000..205b109 Binary files /dev/null and b/bugo.gif differ diff --git a/decode.py b/decode.py new file mode 100644 index 0000000..555f97e --- /dev/null +++ b/decode.py @@ -0,0 +1,40 @@ +vowels = "AEIOU" +def convert(char): + n = int(ord(char)) + encoded_char = chr(n+4) + return encoded_char + +def encode_word(word): + result = "" + for i in range(len(word)): + if i ==0 or i ==len(word)-1: + result +=convert(word[i]) + elif word[i] not in vowels: + result += convert(word[i]) + return result + + + #print(result) + +#encode_word("is") +#encode_word("cOmE") + +# encode string +def encode_string(my_string): + result_list = [] + result ="" + for word in my_string.split(): + + result_list.append(encode_word(word)) + + encoded_result = " ".join(result_list) + return encoded_result + +astring = """ + A SUBSET OF MACHINE LEARNING IS CLOSELY RELATED TO COMPUTATIONAL STATISTICS + WHICH FOCUSES ON MAKING PREDICTIONS USING COMPUTERS. +""" + + + +print(encode_string(astring)) \ No newline at end of file diff --git a/encode.py b/encode.py new file mode 100644 index 0000000..7c30bbe --- /dev/null +++ b/encode.py @@ -0,0 +1,47 @@ +vowels = "AEIOU" +def convert(char): + n = int(ord(char)) + encoded_char = chr(n+4) + return encoded_char + +def encode_word(word): + result = "" + for i in range(len(word)): + if i ==0 or i ==len(word)-1: + result +=convert(word[i]) + elif word[i] not in vowels: + result += convert(word[i]) + return result + + + #print(result) + +#encode_word("is") +#encode_word("cOmE") + +# encode string +def encode_string(my_string): + result_list = [] + result ="" + for word in my_string.split(): + + result_list.append(encode_word(word)) + + encoded_result = " ".join(result_list) + return encoded_result + +astring = """ + A SUBSET OF MACHINE LEARNING IS CLOSELY RELATED TO COMPUTATIONAL STATISTICS + WHICH FOCUSES ON MAKING PREDICTIONS USING COMPUTERS. +""" + + + +print(encode_string(astring)) + + + + + + + diff --git a/ende.py b/ende.py new file mode 100644 index 0000000..398c6b3 --- /dev/null +++ b/ende.py @@ -0,0 +1,42 @@ +vowels = "AEIOU" +def convert(char): + n = int(ord(char)) + encoded_char = chr(n-4) + return encoded_char + +def decode_word(word): + result = "" + for i in range(len(word)): + result += convert(word[i]) + return result + + + #print(result) + + + +# decode string +def decode_string(my_string): + result_list = [] + result ="" + for word in my_string.split(): + + result_list.append(decode_word(word)) + + encoded_result = " ".join(result_list) + return encoded_result + +astring = """ +E PRK XQI EKS MR E KP\] JV JV E[]222 +""" + + + +print(decode_string(astring)) + + + + + + + diff --git a/flip.py b/flip.py new file mode 100644 index 0000000..c3a92d6 --- /dev/null +++ b/flip.py @@ -0,0 +1,27 @@ +import random +def winning(Alice,Bob): + HTH = 0 + HTT = 0 + numberOfTrials = 10000 + + for t in range( numberOfTrials ): + myList = [ random.randint(0,1), random.randint(0,1), random.randint(0,1) ] + flips = 3 + HTHflips = HTTflips = 0 + + while HTHflips == 0 or HTTflips == 0: + if HTHflips == 0 and myList[flips-3:flips] == [1,0,1]: + HTHflips = flips + if HTTflips == 0 and myList[flips-3:flips] == [1,0,0]: + HTTflips = flips + myList.append(random.randint(0,1)) + flips += 1 + + HTH += HTHflips + HTT += HTTflips + + + print ('HTT :', numberOfTrials, HTT, float(HTT)/numberOfTrials) + print ('HTH :', numberOfTrials, HTH, float(HTH)/numberOfTrials) + +winning("Alice","Bob") \ No newline at end of file diff --git a/penny.py b/penny.py new file mode 100644 index 0000000..5d8f5f7 --- /dev/null +++ b/penny.py @@ -0,0 +1,30 @@ +from __future__ import print_function +import random +from time import sleep + +first = random.choice([True, False]) + +you = '' +if first: + me = ''.join(random.sample('HT'*3, 3)) + print('I choose first and will win on first seeing {} in the list of tosses'.format(me)) + while len(you) != 3 or any(ch not in 'HT' for ch in you) or you == me: + you = input('What sequence of three Heads/Tails will you win with: ') +else: + while len(you) != 3 or any(ch not in 'HT' for ch in you): + you = input('After you: What sequence of three Heads/Tails will you win with: ') + me = ('H' if you[1] == 'T' else 'T') + you[:2] + print('I win on first seeing {} in the list of tosses'.format(me)) + +print('Rolling:\n ', end='') +rolled = '' +while True: + rolled += random.choice('HT') + print(rolled[-1], end='') + if rolled.endswith(you): + print('\n You win!') + break + if rolled.endswith(me): + print('\n I win!') + break + sleep(1) \ No newline at end of file diff --git a/question two b/question two new file mode 100644 index 0000000..61d29e4 --- /dev/null +++ b/question two @@ -0,0 +1 @@ +def encode() \ No newline at end of file diff --git a/rand.py b/rand.py new file mode 100644 index 0000000..c6ed27d --- /dev/null +++ b/rand.py @@ -0,0 +1,28 @@ +import random +def winning(Alice,Bob): + + bob_count = 0 + alice_count = 0 + myList = [] + i = 0 + numberOfTosses = 1000000 + + while i < numberOfTosses: + myList.append(random.randint(0,1)) + i += 1 + + for i in range (len(myList)): + + if i+2 >= len(myList): + break + + if myList[i] == Alice[0] and myList[i+1] == Alice[1] and myList[i+2] == Alice[2]: + alice_count +=1 + + if myList[i] == Bob[0] and myList[i+1] == Bob[1] and myList[i+2] == Bob[2]: + bob_count +=1 + + print ('HTT :' ,numberOfTosses, alice_count, numberOfTosses/alice_count) + print ('HTH :' ,numberOfTosses, bob_count, numberOfTosses/bob_count) + +winning((1,1,1),(0,1,1)) \ No newline at end of file diff --git a/testmat.py b/testmat.py new file mode 100644 index 0000000..e82dd2b --- /dev/null +++ b/testmat.py @@ -0,0 +1,56 @@ +# importing all necessary libraries +from itertools import count +import random +import matplotlib +from matplotlib import animation +import matplotlib.pyplot as plt +from matplotlib.animation import FuncAnimation +import pandas as pd +#import numpy as np +import re +import os +import datetime +#import seaborn as sns +#%matplotlib qt + +# add random points for each line +bugolobi = pd.read_csv('bugolobi_hourly_average_pm25.csv') +bunamwaya = pd.read_csv('bunamwaya_hourly_average_pm25.csv') +kiwafu = pd.read_csv('kiwafu_hourly_average_pm25.csv') +makerere = pd.read_csv('makerere_hourly_average_pm25.csv') + +myvar = count(0, 3) + +# subplots() function you can draw +# multiple plots in one figure +fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(10, 5)) + +# set limit for x and y axis +axes.set_ylim(0, 100) +axes.set_xlim(0, 24) + +# style for plotting line +plt.style.use("ggplot") + +# create 5 list to get store element +# after every iteration +x1, y1, y2, y3, y4 = [], [], [], [], [] +myvar = count(0, 3) + +def animate(i): + x1.append(next(myvar)) + y1.append((bugolobi[i])) + y2.append((bunamwaya[i])) + y3.append((kiwafu[i])) + y4.append((makerere[i])) + + axes.plot(x1, y1, color="red") + axes.plot(x1, y2, color="gray") + axes.plot(x1, y3, color="blue") + axes.plot(x1, y4, color="green") + + +# set ani variable to call the +# function recursively +anim = FuncAnimation(fig, animate, interval=30) +anim.save('bugo.gif',writer='imagemagick') \ No newline at end of file diff --git a/uu.py b/uu.py new file mode 100644 index 0000000..4e25180 --- /dev/null +++ b/uu.py @@ -0,0 +1,7 @@ +y =[] +for i in range(10,-1): + y.append(i) + +print(y) + +print(2) \ No newline at end of file diff --git a/winner.py b/winner.py new file mode 100644 index 0000000..ee724be --- /dev/null +++ b/winner.py @@ -0,0 +1,31 @@ +import random +def winning(Alice,Bob): + alice_wins = 0 + bob_wins = 0 + numberOfTrials = 10000 + + for t in range( numberOfTrials ): + myList = [ random.randint(0,1), random.randint(0,1), random.randint(0,1) ] + flips = 3 + bob_count =alice_count = 0 + + while alice_count == 0 or bob_count == 0: + if alice_count == 0 and myList[flips-3:flips] == Alice: + alice_count = flips + if bob_count == 0 and myList[flips-3:flips] == Bob: + bob_count = flips + myList.append(random.randint(0,1)) + flips += 1 + + alice_wins += alice_count + bob_wins += bob_count + number_of_wins = bob_wins+alice_wins + alice_prob =alice_wins/number_of_wins + bob_prob =bob_wins/number_of_wins + + + print ('Alice wins :', alice_wins,"Alice probability", alice_prob) + print ('Bob wins :', bob_wins, "lice probability",bob_prob) + return((alice_wins,alice_prob),(bob_wins,bob_prob)) + +print(winning([1,0,1],[1,1,1])) \ No newline at end of file