8000 added comments to answers for week 3 · zfoxpython/intro-to-python@9da8a85 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9da8a85

Browse files
committed
added comments to answers for week 3
1 parent 4da0c0b commit 9da8a85

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
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.")

0 commit comments

Comments
 (0)
0