8000 updated chapter numbers · coderwxy/book1-exercises@5ba6f52 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ba6f52

Browse files
committed
updated chapter numbers
1 parent f249d71 commit 5ba6f52

File tree

117 files changed

+317
-317
lines changed

Some content is hidden

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

117 files changed

+317
-317
lines changed

refactor/chp02/2-4.py renamed to refactor/chp01/1-1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 2.4 review exercises
1+
# 1.1 review exercises
22

33

44
''' The following line won't run because of a syntax error '''

refactor/chp02/2-5.py renamed to refactor/chp01/1-2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 2.5 review exercises
1+
# chapter 1 review exercises
22

33
# The following lines can also be typed
44
# directly into the interactive window as well:

refactor/chp03/3-1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 3.1 review exercises
2+
3+
print('There are "double quotes" in this string.')
4+
5+
print("This string's got an apostrophe.")
6+
7+
print('''This string was written on multiple lines,
8+
and it displays across multiple lines''')
9+
10+
print("This one-line string was written out \
11+
using multiple lines")

refactor/chp03/3-2.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 3.2 review exercises
2+
3+
4+
# Display the number of letters in the string
5+
my_word = "antidisestablishmentarianism"
6+
print(len(my_word))
7+
8+
# Concatenate two strings together
9+
string_left = "bat"
10+
string_right = "man"
11+
print(string_left + string_right)
12+
13+
# Display two strings together, with a space in between
14+
string_one = "heebie"
15+
string_two = "jeebies"
16+
print(string_one, string_two)
17+
18+
19+
# Use subscripting to display part of a string
20+
print("bazinga"[2:6])
21+
22+
23+
# A more advanced way to do the above example would be:
24+
my_string = "bazinga"
25+
start_index = 2
26+
print(my_string[start_index:len(my_string) - start_index + 1])

refactor/chp03/3-3.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 3.3 review exercises
2+
3+
# Take input from the user and display that input back
4+
my_input = input("Type something: ")
5+
print(my_input)
6+
7+
# Display the input string converted to lower-case letters
8+
print(my_input.lower())

refactor/chp04/first_letter.py renamed to refactor/chp03/first_letter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 4.3 first_letter.py
1+
# chapter 3 first_letter.py
22
# Return the upper-case first letter entered by the user
33

44
user_input = input("Tell me your password: ")

refactor/chp04/4-1.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
# 4.1 review exercises
22

3-
print('There are "double quotes" in this string.')
43

5-
print("This string's got an apostrophe.")
4+
# Store an integer as a string
5+
my_integer_string = "6"
66

7-
print('''This string was written on multiple lines,
8-
and it displays across multiple lines''')
7+
# Convert the 'integer' string into an int object using int()
8+
# Multiply the integer by 7 and display the result
9+
print(int(my_integer_string) * 7)
910

10-
print("This one-line string was written out \
11-
using multiple lines")
11+
12+
# Store a floating-point number as a string
13+
my_float_string = "6.01"
14+
15+
# Convert the 'float' string into a number using float()
16+
# Multiply the number by 7 and display the result
17+
print(float(my_float_string) * 7)
18+
19+
20+
# Create a string and an int object, then display them together
21+
my_string = "mp"
22+
my_int = 3
23+
print(my_string + str(my_int))

refactor/chp04/4-2.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
# 4.2 review exercises
22

3+
weight = 0.2
4+
animal = "newt"
35

4-
# Display the number of letters in the string
5-
my_word = "antidisestablishmentarianism"
6-
print(len(my_word))
6+
# Concatenate a number and a string in one print statement
7+
print(str(weight) + " kg is the weight of the newt.")
78

8-
# Concatenate two strings together
9-
string_left = "bat"
10-
string_right = "man"
11-
print(string_left + string_right)
9+
# Use format() to print a number and a string inside of another string
10+
print("{} kg is the weight of the {}.".format(weight, animal))
1211

13-
# Display two strings together, with a space in between
14-
string_one = "heebie"
15-
string_two = "jeebies"
16-
print(string_one, string_two)
12+
# Use format() to add objects inside a string using index numbers
13+
# (Here we reversed the arguments - just because we could.)
14+
print("{1} kg is the weight of the {0}.".format(animal, weight))
1715

18-
19-
# Use subscripting to display part of a string
20-
print("bazinga"[2:6])
21-
22-
23-
# A more advanced way to do the above example would be:
24-
my_string = "bazinga"
25-
start_index = 2
26-
print(my_string[start_index:len(my_string) - start_index + 1])
16+
# Use format() to print new objects inside a string
17+
print("{} kg is the weight of the {}.".format(0.2, "newt"))

refactor/chp04/4-3.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
# 4.3 review exercises
22

3-
# Take input from the user and display that input back
4-
my_input = input("Type something: ")
5-
print(my_input)
63

7-
# Display the input string converted to lower-case letters
8-
print(my_input.lower())
4+
# Cannot find the string "a" in the string "AAA":
5+
print("AAA".find("a"))
6+
7+
8+
# Try to find a number inside a string;
9+
# use str() to convert the number first
10+
version = "version 2.0"
11+
v_num = 2.0
12+
print(version.find(str(v_num)))
13+
14+
15+
# Try to find an upper-case "X" in user input:
16+
my_input = input("Type something: ")
17+
print(my_input.find("X"))

refactor/chp05/translate.py renamed to refactor/chp04/translate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 5.3 translate.py
1+
# chapter 4 translate.py
22
# Turn a user's input into leetspeak
33

44
my_text = input("Enter some text: ")

refactor/chp05/5-1.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
# 5.1 review exercises
22

33

4-
# Store an integer as a string
5-
my_integer_string = "6"
4+
def cube(num):
5+
''' Returns the cube of the input number '''
6+
cube_num = num * num * num
7+
return cube_num
68

7-
# Convert the 'integer' string into an int object using int()
8-
# Multiply the integer by 7 and display the result
9-
print(int(my_integer_string) * 7)
9+
print("0 cubed is", cube(0))
10+
print("2 cubed is", cube(2))
1011

1112

12-
# Store a floating-point number as a string
13-
my_float_string = "6.01"
13+
def multiply(num1, num2):
14+
''' Returns the result of multiplying two input numbers '''
15+
return num1 * num2
1416

15-
# Convert the 'float' string into a number using float()
16-
# Multiply the number by 7 and display the result
17-
print(float(my_float_string) * 7)
18-
19-
20-
# Create a string and an int object, then display them together
21-
my_string = "mp"
22-
my_int = 3
23-
print(my_string + str(my_int))
17+
mult_result = multiply(2, 5)
18+
print("2 times 5 is", mult_result)

refactor/chp05/5-2.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
# 5.2 review exercises
22

3-
weight = 0.2
4-
animal = "newt"
53

6-
# Concatenate a number and a string in one print statement
7-
print(str(weight) + " kg is the weight of the newt.")
4+
# print the integer 2 through 10 using a "for" loop
5+
for i in range(2, 11):
6+
print(i)
87

9-
# Use format() to print a number and a string inside of another string
10-
print("{} kg is the weight of the {}.".format(weight, animal))
118

12-
# Use format() to add objects inside a string using index numbers
13-
# (Here we reversed the arguments - just because we could.)
14-
print("{1} kg is the weight of the {0}.".format(animal, weight))
9+
# print the integer 2 through 10 using a "while" loop
10+
i = 2
11+
while (i < 11):
12+
print(i)
13+
i = i + 1
1514

16-
# Use format() to print new objects inside a string
17-
print("{} kg is the weight of the {}.".format(0.2, "newt"))
15+
16+
def doubles(num):
17+
''' Return the result of multiplying an input number by 2 '''
18+
return num * 2
19+
20+
# Call doubles to double the number 2 three times
21+
my_num = 2
22+
for i in range(0, 3):
23+
my_num = doubles(my_num)
24+
print(my_num)

refactor/chp05/5-3.py

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

refactor/chp06/exponent.py renamed to refactor/chp05/exponent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 6.1 exponent.py
1+
# chapter 5 exponent.py
22
# Receive two input numbers and calculate their power
33

44
base = input("Enter a base: ")

refactor/chp06/invest.py renamed to refactor/chp05/invest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 6.3 invest.py
1+
# chapter 5 invest.py
22
# calculate compound interest to track the growth of an investment
33

44

refactor/chp06/temperature.py renamed to refactor/chp05/temperature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 6.2 temperature.py
1+
# chapter 5 temperature.py
22
# Convert Celsius and Fahrenheit temperatures using functions
33

44

refactor/chp06/6-1.py

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

refactor/chp06/6-2.py

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

refactor/chp07/7-1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 7.1 review exercises
2+
3+
4+
# Test whether these expressions are True or False
5+
print(1 <= 1)
6+
print(1 != 1)
7+
print(1 != 2)
8+
print("good" != "bad")
9+
print("good" != "Good")
10+
print(123 == "123")

refactor/chp07/7-2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 7.2 review exerc 10000 ises
2+
3+
4+
# Test whether these expressions are True or False
5+
print((1 <= 1) and (1 != 1))
6+
print(not (1 != 2))
7+
print(("good" != "bad") or False)
8+
print(("good" != "Good") and not (1 == 1))

refactor/chp07/7-3.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 7.3 review exercises
2+
3+
4+
# Display whether the length of user input is <, > or = 5 characters
5+
my_input = input("Type something: ")
6+
7+
if len(my_input) < 5:
8+
print("Your input is less than 5 characters long.")
9+
elif len(my_input) > 5:
10+
print("Your input is greater than 5 characters long.")
11+
else:
12+
print("Your input is 5 characters long.")

refactor/chp08/8-4.py renamed to refactor/chp07/7-4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 8.4 review exercises
1+
# 7.4 review exercises
22

33

44
# Run in an infinite loop until the user types "q" or "Q"

refactor/chp08/8-5.py renamed to refactor/chp07/7-5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 8.5 review exercises
1+
# 7.5 review exercises
22

33

44
# Ask the user to enter an integer.

refactor/chp08/8-6.py renamed to refactor/chp07/7-6.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 8.6 review exercises
1+
# 7.6 review exercises
22

33
from random import randint
44

refactor/chp08/coin_toss.py renamed to refactor/chp07/coin_toss.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 8.6.2 coin_toss.py
1+
# chapter 7 coin_toss.py
22
# Simulate the results of a series of coin tosses and track the results
33

44
from random import randint

refactor/chp08/coin_toss_alternative.py renamed to refactor/chp07/coin_toss_alternative.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 8.6.2 coin_toss_alternative.py
1+
# chapter 7 coin_toss_alternative.py
22
# Simulate the results of a series of coin tosses and track the results
33

44
from random import randint

refactor/chp08/election.py renamed to refactor/chp07/election.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 8.6.1 election.py
1+
# chapter 7 election.py
22
# Simulate the results of an election using a Monte Carlo simulation
33

44
from random import random

refactor/chp08/factors.py renamed to refactor/chp07/factors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 8.3 factors.py
1+
# chapter 7 factors.py
22
# display all the factors of a number chosen by the user
33

44
num = int(input("Enter a positive integer: "))

0 commit comments

Comments
 (0)
0