Skip to content

Commit a000333

Browse files
committed
2 parents c629906 + 7651ab7 commit a000333

File tree

14 files changed

+227
-33
lines changed

14 files changed

+227
-33
lines changed

session_03/answers/A1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# A1 - Ask for the user's name, if they are called "Bob", print "Welcome Bob!"
22

3+
# Created variable name and assigned the input to it.
4+
# Whatever the user enters as their name will be stored in the name variable.
35
name = input("What is your name?\n")
46

7+
# Checking if the name the user has input is Bob.
8+
# If it is, print "Welcome Bob!"
59
if name == "Bob":
610
print("Welcome Bob!")

session_03/answers/A2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# A2 - Ask for the user's name, if they are not called "Alice", print "You're not Alice!"
22

3+
# Created variable name and assigned the input to it.
4+
# Whatever the user enters as their name will be stored in the name variable.
35
name = input("What is your name?\n")
46

7+
# Checking if the name the user has input is not Alice.
8+
# If it is not Alice, print "You're not Alice!"
59
if name != "Alice":
610
print("You're not Alice!")

session_03/answers/A3.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# A3 - Ask the user for a password, if they enter the password "qwerty123", print "You have successfully logged in".
22
# If they get it wrong, print "Password failure"
33

4-
password = "qwerty123"
4+
# Created variable name and assigned the input to it.
5+
# Whatever the user enters as their password will be stored in the user_guess variable.
56
user_guess = input("What is your password?\n")
7+
# Hardcoded password variable so we can compare this against the user_guess
8+
password = "qwerty123"
69

10+
# Checking if the password is the same as the user_guess.
11+
# If it is the same, print "You have successfully logged in."
712
if user_guess == password:
813
print("You have successfully logged in.")
14+
# If it is not the same, print "Password failure."
915
else:
1016
print("Password failure.")

session_03/answers/A4.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# A4 - Ask the user to enter a number, if the number is even, print "Even", otherwise print "Odd"
22

3+
# Created variable number and assigned the input to it.
4+
# As we will be performing some math on this input, we will need to cast it to an integer.
5+
# Whatever the user enters as their number will be stored in the number variable.
36
number = int(input("Please enter a number to find out if it is even or odd:\n"))
47

8+
# Checking if the number is even, we do this by using the modulus to check if when divided by 2 the remainder is 0
9+
# If it is the same, print(str(number) + " is Even") - as number is an integer, to concatenate, we have to cast to a string.
510
if number % 2 == 0:
611
print(str(number) + " is Even")
12+
# If it is not even, it must be odd so will print(str(number) + " is Odd"), again casting the number to a string.
713
else:
814
print(str(number) + " is Odd")

session_03/answers/A5.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# A5 - Ask the user for 2 different numbers, if the total of the two numbers is over 21, print "Bust" otherwise print "Safe"
22

3+
# Created variable number and assigned the input to it.
4+
# As we will be performing some math on this input, we will need to cast it to an integer.
5+
# Whatever the user enters as their number will be stored in the number_1 variable.
6+
# Repeated the above for number_2
37
number_1 = int(input("Input a number:\n"))
48
number_2 = int(input("Input another number:\n"))
59

10+
# Checking if when both number variables are added together are over 21, print("Bust.")
611
if number_1 + number_2 > 21:
712
print("Bust.")
13+
# if when both number variables are added together are under 21, print("Safe.")
814
else:
915
print("Safe.")

session_04/answers/B10.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# D5 - FizzBuzz – Write a program that prints the numbers from 1 to 100.
1+
# B10 - FizzBuzz – Write a program that prints the numbers from 1 to 100.
22
# For multiples of three, print “Fizz” instead of the number and for multiples of five, print “Buzz”.
33
# For numbers which are multiples of both three and five, print “FizzBuzz”
44

session_05/answers/A5.py renamed to session_05/answers/A11.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# A5 - Rock, Paper, Scissors - Create a simple rock, paper, scissors game which is run against computer.
1+
# A11 - Rock, Paper, Scissors - Create a simple rock, paper, scissors game which is run against computer.
22

33
import random
44

session_06/slides/session_6.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ while times_in_loop <= 10:
197197
x = 1
198198
while x <= 100:
199199
print(x)
200-
times_in_loop = times_in_loop + 1
200+
x = x + 1
201201

202202
for y in range(1, 101):
203203
print(y)

session_08/answers/A2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# A2 - Read the file 'austen.txt' and print the amount of lines in the file
2+
3+
#Option 1
24
total = 0
35
for x in open("austen.txt"):
46
total += 1
7+
58
print(total)
9+
10+
#Option 2
11+
f = open("austen.txt", "r")
12+
count = 0
13+
for x in f:
14+
count += 1
15+
16+
print(count)

session_08/answers/A3.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# A3 - Each line of the file 'numbers.txt' contains a number, write a script to add up all the values in the file
2+
3+
#Option 1
24
total = 0
35
for x in open("numbers.txt"):
46
total += int(x)
7+
58
print(total)
9+
10+
#Option 2
11+
f = open("numbers.txt", "r")
12+
sum = 0
13+
for x in f:
14+
x = int(x)
15+
sum += x
16+
17+
print(sum)

0 commit comments

Comments
 (0)