Skip to content

Commit 6974db2

Browse files
updates to code samples in complex conditions
1 parent 1f82425 commit 6974db2

6 files changed

Lines changed: 62 additions & 41 deletions

‎complex_condition_checks/boolean_variables.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
gpa = float(input('What was your Grade Point Average? '))
33
lowest_grade = float(input('What was your lowest grade? '))
44

5+
# Boolean variables allow you to remember a True/False value
56
if gpa >= .85 and lowest_grade >= .70:
67
honour_roll = True
78
else:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# When you join a hockey team you get your name on the back of the jersey
2+
# but the jersey may not be big enough to hold all the letters
3+
# Ask the user for their first name
4+
5+
# Ask the user for their last name
6+
7+
# if first name is < 10 characters and last name is < 10 characters
8+
# print first and last name on the jersey
9+
# if first name >= 10 characters long and last name is < 10 characters
10+
# print first initial of first name and the entire last name
11+
# if first name < 10 characters long and last name is >= 10 characters
12+
# print entire first name and first initial of last name
13+
# if first name >= 10 characters long and last name is >= 10 characters
14+
# print last name only
15+
16+
# Test with the following values
17+
# first name: Susan last name: Ibach
18+
# output: Susan Ibach
19+
# first name: Susan last name: ReallyLongLastName
20+
# output: Susan R.
21+
# first name: ReallyLongFirstName last name: Ibach
22+
# output: R. Ibach
23+
# first name: ReallyLongFirstName last name: ReallyLongLastName
24+
# output: ReallyLongLastName
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# When you join a hockey team you get your name on the back of the jersey
2+
# but the jersey may not be big enough to hold all the letters
3+
# Ask the user for their first name
4+
first_name = input('Please enter your first name: ')
5+
# Ask the user for their last name
6+
last_name = input('Please enter your last name: ')
7+
8+
# if first name is < 10 characters and last name is < 10 characters
9+
# print first and last name on the jersey
10+
# if first name >= 10 characters long and last name is < 10 characters
11+
# print first initial of first name and the entire last name
12+
# if first name < 10 characters long and last name is >= 10 characters
13+
# print entire first name and first initial of last name
14+
# if first name >= 10 characters long and last name is >= 10 characters
15+
# print last name only
16+
17+
# Check length of first name
18+
if len(first_name) >=10:
19+
long_first_name = True
20+
else:
21+
long_first_name = False
22+
23+
# Check length of last name
24+
if len(last_name) >= 10:
25+
long_last_name = True
26+
else:
27+
long_last_name = False
28+
29+
# Evaluate possible jersey print combinations for different lengths
30+
if long_first_name and long_last_name:
31+
print(last_name)
32+
elif long_first_name:
33+
print(first_name[0:1] + '. ' + last_name)
34+
elif long_last_name:
35+
print(first_name + ' ' + last_name[0:1] + '.')
36+
else:
37+
print(first_name + ' ' + last_name)

‎complex_condition_checks/combine_and_or.py‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎complex_condition_checks/fix_and_or_order_of_operations.py‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎complex_condition_checks/using_in_to_avoide_order_of_operations_errors.py‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)