Skip to content

Commit c6066de

Browse files
committed
Added U1 to U3 code files
0 parents  commit c6066de

10 files changed

+159
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
###########
2+
# bad code
3+
###########
4+
a = 3.1
5+
b = 2.2
6+
c = a * b * b
7+
8+
###########
9+
# good code
10+
###########
11+
pi = 3.1
12+
radius = 2.2
13+
circle_area = pi * radius * radius
14+
15+
###########
16+
# bad comments
17+
###########
18+
pi = 3.1
19+
radius = 2.2
20+
# multiply pi times the radius times the radius
21+
circle_area = pi * radius * radius
22+
23+
###########
24+
# good comments
25+
###########
26+
pi = 3.1
27+
radius = 2.2
28+
# use the formula to calculate the area of a circle
29+
circle_area = pi * radius * radius

u2m1_introducing_python.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
3+2
2+
4/5
3+
print(3+2)
4+
print(4/5)
5+
6+
print(6+7)
7+
print(3/6)

u2m2_giving_names_to_things.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
3+2
2+
4/5
3+
print(3+2)
4+
print(4/5)
5+
6+
print(6+7)
7+
print(3/6)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# initializations
2+
minutes_to_convert = 30
3+
4+
# calculations
5+
hours = int(minutes_to_convert / 60)
6+
minutes = minutes_to_convert % 60
7+
8+
# outputs
9+
print("Hours")
10+
print(hours)
11+
print("Minutes")
12+
print(minutes)

u3m1_string_objects.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
text = "MY 1ST TIME PLAYING WITH STRINGS! &OSIDJOIF@$#@NLOIS*@^%@$ASIDU"
2+
3+
without_cat = text[0:33:1]
4+
print(without_cat)
5+
6+
middle_bit = without_cat[12:len(without_cat):1]
7+
print(middle_bit)
8+
9+
proper_sentence = middle_bit.capitalize()
10+
print(proper_sentence)

u3m2_advanced_string_operations.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
phrase = "Eek, two snake eyes"
2+
num = "1"
3+
4+
num_repeat = num * 4
5+
print(num_repeat)
6+
7+
str_not_num = num_repeat.replace("1", "one")
8+
print(str_not_num)
9+
10+
together = phrase + ": " + str_not_num
11+
print(together)
12+
13+
num_times = together.count("neon")
14+
print(num_times)

u3m3_simple_error_messages.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name = "Ana"
2+
print(name[0])
3+
print(name[1])
4+
print(name[2])
5+
print(name[3])
6+
print(name[-1])

u3m4_tuple_objects.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
initials = ("AA", ("BB", ("CC", "CZ"), "BZ"), "AZ")
2+
print(initials[1])
3+
print(initials[1][1])
4+
print(initials[1][1][1])
5+
6+
summer = "hot"
7+
winter = "cold"
8+
print(summer)
9+
print(winter)
10+
(summer, winter) = (winter, summer)
11+
print(summer)
12+
print(winter)

u3m5_interacting_with_the_user.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
print("hello")
2+
print(5*2+3**5)
3+
print("new"+"ton")
4+
5+
top = 22
6+
bottom = 7
7+
pi_approx = top/bottom
8+
print(pi_approx)
9+
print(top,"/",bottom,"=",pi_approx)
10+
to_print = str(top)+"/"+str(bottom)+"="+str(pi_approx)
11+
print(to_print)
12+
13+
# input stored as a string - concatenate
14+
a = input("Enter one number: ")
15+
b = input("Enter another number: ")
16+
print(a+b)
17+
18+
# input stored as a string - convert to int
19+
a = int(input("Enter one number: "))
20+
b = int(input("Enter another number: "))
21+
print(a+b)
22+
23+
#############
24+
# quick check
25+
#############
26+
27+
# get user input
28+
day = input("What day of the week? ")
29+
num = int(input("How many times? "))
30+
31+
# show the phrase
32+
print("It's", day*num)

u3m6_exercise_name_mashup.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# get user input
2+
name1 = input("Enter one name: ")
3+
name2 = input("Enter another name: ")
4+
5+
space = name1.find(" ")
6+
name1_first = name1[0:space]
7+
name1_last = name1[space+1:len(name1)]
8+
space = name2.find(" ")
9+
name2_first = name2[0:space]
10+
name2_last = name2[space+1:len(name2)]
11+
12+
# find combinations
13+
name1_first_1sthalf = name1_first[0:int(len(name1_first)/2)]
14+
name1_first_2ndhalf = name1_first[int(len(name1_first)/2):len(name1_first)]
15+
name1_last_1sthalf = name1_last[0:int(len(name1_last)/2)]
16+
name1_last_2ndhalf = name1_last[int(len(name1_last)/2):len(name1_last)]
17+
18+
name2_first_1sthalf = name2_first[0:int(len(name2_first)/2)]
19+
name2_first_2ndhalf = name2_first[int(len(name2_first)/2):len(name2_first)]
20+
name2_last_1sthalf = name2_last[0:int(len(name2_last)/2)]
21+
name2_last_2ndhalf = name2_last[int(len(name2_last)/2):len(name2_last)]
22+
23+
new_name1_first = name1_first_1sthalf + name2_first_2ndhalf
24+
new_name1_last = name1_last_1sthalf + name2_last_2ndhalf
25+
new_name2_first = name2_first_1sthalf + name1_first_2ndhalf
26+
new_name2_last = name2_last_1sthalf + name1_last_2ndhalf
27+
28+
# print results
29+
print(new_name1_first, new_name1_last)
30+
print(new_name2_first, new_name2_last)

0 commit comments

Comments
 (0)