Skip to content
This repository was archived by the owner on May 23, 2021. It is now read-only.

Commit 7eb90be

Browse files
authored
Add files via upload
1 parent 9834d40 commit 7eb90be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+901
-0
lines changed

FindtheError.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
my_string = "hello!"
2+
3+
# One of the two lines below will cause an error.
4+
# Each line is an attempt to replace the first
5+
# letter of myString with H. Comment out the
6+
# line you think is incorrect.
7+
#my_string[0] = "H"
8+
my_string = "H" + my_string[1:]
9+
10+
print my_string

FirstCharacter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def first_character(chars):
2+
return chars[0]
3+
def all_but_first_character(chars):
4+
return chars[1:]
5+
6+
print first_character("hello")
7+
print all_but_first_character("hello")

FiveNumbers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
numList = []
2+
result = 0
3+
4+
for i in range(5):
5+
num = int(input("Enter a number: "))
6+
numList = numList + [num]
7+
print numList
8+
9+
for i, item in enumerate(numList):
10+
result = result + item
11+
12+
print "\n\nAddition Result: " + str(result)

FixThisProgram (1).py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
instrument = "kazoo"
2+
age = str(7)
3+
4+
print "I have played the " + instrument + " since I was " + age + " years old."

FixThisProgram! (1).py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
print "Hi there!"
2+
print "My favorite color is magenta."

FixThisProgram!.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
This program takes two values and prints their sum.
3+
"""
4+
5+
def add_nums():
6+
num1 = 5
7+
num2 = 6
8+
print num1 + num2
9+
10+
add_nums()

FixThisProgram.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
can_juggle = True
2+
3+
# The code below has problems. See if
4+
# you can fix them!
5+
6+
if can_juggle:
7+
print "I can juggle!"
8+
else:
9+
print "I can't juggle."

FixThisTuple.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
my_tuple = (0, 1, 2, "hi", 4, 5)
2+
3+
# Your code here...
4+
5+
print my_tuple[:3] + (3,) + my_tuple[4:]

ForLoop+WhileLoop.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# You can also nest for loops with
2+
# while loops. Check it out!
3+
4+
for i in range(4):
5+
print "For loop: " + str(i)
6+
x = i
7+
while x >= 0:
8+
print " While loop: " + str(x)
9+
x = x - 1

ForLoopsandLists,Part2.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
This program uses for loops to iterate through a list and uses the range
3+
values in the for loop as the index values to print each list element.
4+
"""
5+
6+
first_list = [1, 10, 3]
7+
second_list = [2, 5, 6]
8+
9+
# This for loop uses the length of the list to determine the index values
10+
for index in range(len(first_list)):
11+
print "Looking at index: " + str(index)
12+
thing_in_first_list = first_list[index]
13+
thing_in_second_list = second_list[index]
14+
15+
print " 1st list has: " + str(thing_in_first_list)
16+
print " 2nd list has: " + str(thing_in_second_list)
17+
if (thing_in_first_list > thing_in_second_list):
18+
print " thing in 1st list was bigger"
19+
elif (thing_in_second_list > thing_in_first_list):
20+
print " thing in 2nd list was bigger"

0 commit comments

Comments
 (0)