Skip to content

Commit

Permalink
more questions
Browse files Browse the repository at this point in the history
  • Loading branch information
pronapro committed Aug 1, 2021
1 parent 7923ff5 commit 0b0f2e5
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 0 deletions.
25 changes: 25 additions & 0 deletions al.py
Original file line number Diff line number Diff line change
@@ -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)
Binary file added bugo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions decode.py
Original file line number Diff line number Diff line change
@@ -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))
47 changes: 47 additions & 0 deletions encode.py
Original file line number Diff line number Diff line change
@@ -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))







42 changes: 42 additions & 0 deletions ende.py
Original file line number Diff line number Diff line change
@@ -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))







27 changes: 27 additions & 0 deletions flip.py
Original file line number Diff line number Diff line change
@@ -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")
30 changes: 30 additions & 0 deletions penny.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions question two
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def encode()
28 changes: 28 additions & 0 deletions rand.py
Original file line number Diff line number Diff line change
@@ -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))
56 changes: 56 additions & 0 deletions testmat.py
Original file line number Diff line number Diff line change
@@ -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')
7 changes: 7 additions & 0 deletions uu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
y =[]
for i in range(10,-1):
y.append(i)

print(y)

print(2)
31 changes: 31 additions & 0 deletions winner.py
Original file line number Diff line number Diff line change
@@ -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]))

0 comments on commit 0b0f2e5

Please sign in to comment.