Holiday Coding Tasks
Holiday Coding Tasks
count = 0
arr = ["a","b","c","c"]
string = []
def substring(string,arr,count):
for i in range (len(arr)):
for j in range (len(arr[i])):
if arr[j]!=arr[j+1]:
count==count+1
if arr[j+1]!=arr[j+2]:
count==count+1
string.append(arr[j])
string.append(arr[j+1])
string.append(arr[j+2])
print(string)
substring(string,arr,count)
factorial finder
n = int(input("Enter a number:"))
def f(n):
for i in range (1):
f = n-1
print(n*f)
for j in range (n-1):
f = f-1
print(n*f)
f(n)
import random
enter = input("Press W to start:")
arr = [1,2,3,4,5,6,7,8,9,10]
w = []
op = ["+","-","/"]
def question(enter):
if enter == "W":
for i in range(8):
n=random.randint(1,16)
w.append(n)
print(n)
computer = random.choice(op)
print(computer)
n2 = random.randint(1,16)
print(n2)
q2 = int(input("What is the answer:"))
if computer == "+":
if q2 != n+n2:
if q2 == True:
count = 1
print("Incorrect lol")
elif computer == "-" and q2 != n-n2:
print("Incorrect lol")
elif computer == "/":
if q2 != n/n2:
print("Incorrect lol")
question(enter)
Arithmetic test
import random
file.write(name)
my_variable = "\n".join(name)
file.write(Class)
my_variable2 = "\n".join(Class)
def questions(name):
score = 0
num1 = random.randint(1, 20)
num2 = random.randint(1, 20)
operator = random.choice(['+', '-', '*', '/'])
question = f"{num1} {operator} {num2}"
value = int(input(question))
answer = eval(question)
if value == answer:
score = score+1
print("Correct")
else:
print("Incorrect")
print(f"Your score is {score}")
for i in range(10):
questions(name)
Fruit Machine
import random
v = input("w:")
array = ["Cherry","Bell","Lemon","Orange", "Star", "Skull"]
def rolls(v):
credit = 1
print("Rolling......")
credit = credit-0.20
for i in range(1):
choice = random.choice(array)
choice2 = random.choice(array)
print(f"Nice you rolled two {choice}")
if choice==choice2:
credit = credit+0.50
print(f"congrats you are now on {credit}")
for i in range(1):
choice = random.choice(array)
choice2 = random.choice(array)
choice3 = random.choice(array)
if choice=arr[1] and choice2 == arr[1] and choice3 == arr[1]:
print(f"jackpot your on {credit}")
print(f"Nice you rolled three {choice}")
if choice==choice2 and choice2 == choice3:
credit = credit+1
print(f"congrats you are now on {credit}")
elif choice==arr[1] and choice2 == arr[1] and choice3 == arr[1]:
print(f"jackpot your on {credit}")
rolls(v)
w = input("Enter a name:")
def names(w):
for i in range(6):
name = input("Enter a name:")
if len(name)>=6:
myfile = open("names.txt","w")
myfile.write(name)
myfile.close()
else:
print("Too short")
names(w)
arr = [1,2,3]
myfile = open("names.txt","r")
kn = input("Enter a name:")
def sequence(kn):
if kn in myfile:
print(kn,arr[0])
else:
print(kn,arr[+1])
myfile = open("names.txt","w")
myfile.write(f"{name}{age}\n{name1}{age2}")
myfile = open("names.txt","r")
print(myfile.read())
myfile.close()
myfile = open("users.txt","w")
myfile.write(variable)
myfile.close()
def login():
username = input("Enter your username:")
myfile = open("users.txt","r")
if username in myfile:
myfile.close()
myfile = open("users.txt","w")
myfile.write("snowman5")
myfile.close()
myfile = open("users.txt","r")
password = input("Enter your password:")
if password in myfile:
menu=input(f"Welcome {variable} what would you like to do?")
myfile.close()
def sta():
num = input("How many students do you have")
for i in range(len(num)):
name = input("Enter student name:")
ID = input("Enter student ID:")
myfile = open("students.txt","w")
myfile.write(name,"\n")
myfile.write(ID)
myfile.close()
student = input("By enterring an ID you cam view a student:")
myfile = open("students.txt.r")
if student in myfile:
print(myfile)
myfile.close()
sta()
INtroduction to HTML
<html>
<head>
<title>Baileys superstore</title>
<style>
h1{font-family:arial;
}
.customerQoute{background-color:#E8C3E1;
}
document.getElementbyId("intro"){
color:#540c07;
}
</style>
</head>
<body>
<p id = "intro">
Welcome to baileys superstore
<script>
var DarkRed = #540c07
</script>
<h1>Hello World</h1>
<div class = "customerQuote">
</div>
</body>
</html>
Exercise 2
<html>
<head>
<title>The Title</title>
</head>
<body>
<a href "https://www.google.co.uk/" target =_blank title = "Google link">
<button style="font-size:40px; background-color:#064216;color:ffffff; border-
radius:px;border-color:#ff0000" >Google</button>
</a>
<form>
<div>
<label> firstname:</label>
<input type = "text" placeholder = "e.g Diana">
</div>
<br>
<div>
<label> lastname:</label>
<input type = "text" placeholder = "e.g Daylami">
</div>
<br>
<label> username:</label>
<input type = "text" placeholder = "e.g iWatchBratz">
</div>
<br>
<div>
<label> password:</label>
<input type = "text" placeholder = "e.g tallmansofine">
</div>
<br>
<button style = "font-family:arial; background-color:green;border-color:#ff0000
border-radius;45px">Register</button>
</form>
<script>
function validPassword() {
var reset = "Please try again:"
var password = getElementById("password");
var PreferredPassword = password.value;
if (/[A-Z].test(password))
return reset
}
</script>
</body>
</html>