Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rename folders and files#2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
somacdivad merged 11 commits intomasterfromrename-folders-and-files
May 21, 2018
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,4 +2,5 @@ py3venv
env
*.pyc
__pycache__/
.DS_Store
.DS_Store
.vscode
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 7 additions & 4 deletionschp01/1-1.py → ch02-getting-started/1-2-4.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
# 1.1 review exercises
# 1.2.4 - Screw Things Up
# Solutions to review exercies


''' The following line won't run because of a syntax error '''
# Exercise 1
# The following line won't run because of a syntax error
print("hi)

# We didn't close the double quotes at the end of the string.
# The line above needed to have been:
# print("hi")


# Exercise 2
''' The following lines won't run properly,
even if the syntax error in the line above is corrected,
because of a run-time error '''
Expand All@@ -17,5 +20,5 @@
# We meant to print the string "hello";
# a variable named 'hello' doesn't exist yet.
# This line could have been:
#myString = "hello"
# print(myString)
#my_string = "hello"
# print(my_string)
15 changes: 15 additions & 0 deletionsch02-getting-started/1-2-5.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
# 1.2.5 - Store a Variable
# Solutions to review exercies


# Exercise 3 (exercises 1 and 2 are done in interactive window)
# This solution works for Exercises 1 and 2 by typing the same lines into the
# interactive window.

# display a string directly
print("hello")


# display the contents of a string variable
my_string = "hi"
print(my_string)
20 changes: 20 additions & 0 deletionsch04-fundamentals-strings-and-methods/1-4-0.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
# 1.4 - Fundamentals: Strings and Methods
# Solutions to review exercies


# Exercise 1
print('There are "double quotes" in this string.')


# Exercise 2
print("This string's got an apostrophe.")


# Exercise 3
print('''This string was written on multiple lines,
and it displays across multiple lines''')


# Exercise 4
print("This one-line string was written out \
using multiple lines")
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
# 3.2 review exercises
# 1.4.1 - Mess Around With Your Words
# Solutions to review exercies


# Exercise 1
# Display the number of letters in the string
my_word = "antidisestablishmentarianism"
print(len(my_word))

# Exercise 2
# Concatenate two strings together
string_left = "bat"
string_right = "man"
print(string_left + string_right)

# Exercise 3
# Display two strings together, with a space in between
string_one = "heebie"
string_two = "jeebies"
print(string_one, string_two)


# Exercise 4
# Use subscripting to display part of a string
print("bazinga"[2:6])


# A more advanced way to do the above example would be:
my_string = "bazinga"
start_index = 2
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
# 3.3 review exercises
# 1.4.2 - Use Objects and Methods
# Solutions to review exercies


# Exercise 1
# Take input from the user and display that input back
my_input = input("Type something: ")
print(my_input)


# Exercise 2
# Display the input string converted to lower-case letters
print(my_input.lower())
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
# chapter 3 first_letter.py
# 1.4.3 - Assignment: Pick Apart Your User's Input
# Solution to assignment


# Return the upper-case first letter entered by the user

user_input = input("Tell me your password: ")
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
# 4.1 review exercises
# 1.5.0 - Fundamentals: Working with Strings
# Solutions to review exercies


# Exercise 1
# Store an integer as a string
my_integer_string = "6"

Expand All@@ -9,6 +11,7 @@
print(int(my_integer_string) * 7)


# Exercise 2
# Store a floating-point number as a string
my_float_string = "6.01"

Expand All@@ -17,6 +20,7 @@
print(float(my_float_string) * 7)


# Exercise 3
# Create a string and an int object, then display them together
my_string = "mp"
my_int = 3
Expand Down
15 changes: 13 additions & 2 deletionschp04/4-2.py → ...undamentals-working-with-strings/1-5-1.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
# 4.2 review exercises
# 1.5.1 - Streamline Your Print Statements
# Solutions to review exercies


# Exercise 1
weight = 0.2
animal = "newt"

# Concatenate a number and a string in one print statement
print(str(weight) + " kg is the weight of the newt.")


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


# Exercise 3
# Use format() to add objects inside a string using index numbers
# (Here we reversed the arguments - just because we could.)
print("{1} kg is the weight of the {0}.".format(animal, weight))


# Exercise 4
# Use format() to print new objects inside a string
print("{} kg is the weight of the {}.".format(0.2, "newt"))

# Use formatted string literal to reference new objects inside a string

# Exercise 5
# Use formatted string literal to reference objects inside a string
print(f"{weight} kg is the weight of the {animal}.")
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
# 4.3 review exercises
# 1.5.2 - Find a String in a String
# Solutions to review exercies


# Exercise 1
# Cannot find the string "a" in the string "AAA":
print("AAA".find("a"))


# Exercise 2
# Try to find a number inside a string;
# use str() to convert the number first
version = "version 2.0"
v_num = 2.0
print(version.find(str(v_num)))


# Exercise 3
# Try to find an upper-case "X" in user input:
my_input = input("Type something: ")
print(my_input.find("X"))
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
# chapter 4 translate.py
# 1.5.3 - Assignment: Turn Your User Into a l33t h4x0r
# Solution to assignment


# Turn a user's input into leetspeak

my_text = input("Enter some text: ")
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
# chapter 5 exponent.py
# 1.6.1 - Assignment: Perform Calculations on User Input
# Solution to Assignment


# Receive two input numbers and calculate their power

base = input("Enter a base: ")
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
# 5.1 review exercises
# 1.6.3 - Functions Summary
# Solutions to review exercises


# Exercise 1
def cube(num):
''' Returnsthe cube of the input number '''
"""Returnthe cube of the input number."""
cube_num = num * num * num
return cube_num


print("0 cubed is", cube(0))
print("2 cubed is", cube(2))


# Exercise 2
def multiply(num1, num2):
''' Returnsthe result of multiplying two input numbers '''
"""Returnthe result of multiplying two input numbers."""
return num1 * num2


mult_result = multiply(2, 5)
print("2 times 5 is", mult_result)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
# chapter 5 temperature.py
# Convert Celsius and Fahrenheit temperatures using functions
# 1.6.4 - Assignment: Convert temperatures
# Solution to assignment


# Convert Celsius and Fahrenheit temperatures using functions

def convert_cel_to_far(cel_temp):
far_temp = cel_temp * 9 / 5 + 32
Expand All@@ -11,6 +13,7 @@ def convert_far_to_cel(far_temp):
cel_temp = (far_temp - 32) * 5 / 9
return cel_temp


temp1 = 72
print("{} degrees F = {} degrees C".format(temp1, convert_far_to_cel(temp1)))

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
# 5.2 review exercises
# 1.6.5 - Run in Circles
# Solutions to review exercises


# Exercise 1
# print the integer 2 through 10 using a "for" loop
for i in range(2, 11):
print(i)


# Exercise 2
# print the integer 2 through 10 using a "while" loop
i = 2
while (i < 11):
print(i)
i = i + 1


# Exercise 3
def doubles(num):
'''Return the result of multiplying an input number by 2 '''
"""Return the result of multiplying an input number by 2."""
return num * 2


# Call doubles to double the number 2 three times
my_num = 2
for i in range(0, 3):
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
# chapter 5 invest.py
# calculate compound interest to track the growth of an investment
# 1.6.6 - Assignment: Track Your Investments
# Solution to Assignment


# calculate compound interest to track the growth of an investment

def invest(amount, rate, time):
print("principal amount: ${}".format(amount))
Expand All@@ -10,5 +12,6 @@ def invest(amount, rate, time):
print("year {}: ${}".format(t, amount))
print()


invest(100, .05, 8)
invest(2000, .025, 5)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
# 7.1 review exercises
# 1.8.1 - Compare Values
# Solutions to review exercises


# Test whether these expressions are True or False

print(1 <= 1)
print(1 != 1)
print(1 != 2)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
# 7.2 review exercises
# 1.8.2 - Add Some Logic
# Solutions to review exercises


# Test whether these expressions are True or False

print((1 <= 1) and (1 != 1))
print(not (1 != 2))
print(("good" != "bad") or False)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
# 7.3 review exercises
# 1.8.3 - Control the Flow of Your Program
# Solutions to review exercises


# Display whether the length of user input is <, > or = 5 characters

my_input = input("Type something: ")

if len(my_input) < 5:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
# chapter 7 factors.py
# 1.8.4 - Assignment: Find the Factors of a Number
# Solution to assignment


# display all the factors of a number chosen by the user

num = int(input("Enter a positive integer: "))
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
# 7.4 review exercises
# 1.8.5 - Break Out of the Pattern
# Solutions to review exercises


# Exercise 1
# Run in an infinite loop until the user types "q" or "Q"
while True:
my_input = input('Type "q" or "Q" to quit: ')
if my_input.upper() == "Q":
break


# Exercise 2
# Display every number from 1 through 50 except multiples of 3
for i in range(1, 51):
if i % 3 == 0:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
# 7.5 review exercises
# 1.8.6 - Recover From Errors
# Solution to review exercises


# Ask the user to enter an integer.
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp