Skip to content

Commit db08155

Browse files
committed
aaa
1 parent e49cbdf commit db08155

File tree

7 files changed

+29
-4
lines changed

7 files changed

+29
-4
lines changed

python-for-beginners/04 - String variables/string_functions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
# count will count the number of occurrences of the value specified
1616
# in the string, in this case how many times the letter 'a' appears
1717
print(sentence.count('a'))
18+
19+
print(sentence[5:7])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from array import array
2-
scores = array('d')
2+
scores = array('i')
33
scores.append(97)
44
scores.append(98)
55
print(scores)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
names = ['Christopher', 'Susan']
22
print(len(names)) # Get the number of items
33
names.insert(0, 'Bill') # Insert before index
4+
names.append('Nacho')
5+
print(names)
6+
names.sort()
47
print(names)

python-for-beginners/11 - Collections/ranges.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
names = ['Susan', 'Christopher', 'Bill']
2-
presenters = names[0:2] # Get the first two items
2+
presenters = names[:2] # Get the first two items
33
# Starting index and number of items to retrieve
44

55
print(names)
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
for name in ['Christopher', 'Susan']:
1+
names = ['Christopher', 'Susan']
2+
for name in names:
23
print(name)
4+
5+
for index in range(0,len(names)):
6+
print(names[index])

python-for-beginners/12 - Loops/number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# First parameter is the starter
33
# Second indicates the number of numbers to create
44
# range(0, 2) creates [0, 1]
5-
for index in range(0, 2):
5+
for index in range(3, 5):
66
print(index)

python-for-beginners/13 - Functions/code_challenge.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@
1515
# BONUS: Test your function with the values 6, 4 and divide
1616
# Have your function return an error message when invalid values are received
1717

18+
def calculator(x,y,operator):
19+
result = 0
20+
if operator.lower()=='add':
21+
result = x + y
22+
elif operator.lower()=='substract':
23+
result = x - y
24+
elif operator.lower()=='divide':
25+
result = x / y
26+
27+
return result
28+
29+
print(calculator(6,4,'add'))
30+
31+
print(calculator(6,4,'substract'))
32+
33+
print(calculator(6,4,'divide'))

0 commit comments

Comments
 (0)