Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode/
*.xml
*.iml
4 changes: 2 additions & 2 deletions 1_beginner/chapter1/examples/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# This is a single line comment

'''
"""
This is a
multi-line
comment
'''
"""

"""
This is also a multi-line
Expand Down
6 changes: 3 additions & 3 deletions 1_beginner/chapter1/examples/printing.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Printing

# Strings can be in single or double quotes
print('Message')
print("Message")
print("Message")

# You can print with multiple arguments
# Arguments are separated by a space by default
print('Message', 'with', 'arguments')
print("Message", "with", "arguments")

# You can use string concatenation ("adding")
# to put strings together (just be careful about spacing!)
print('Message' + 'with' + 'concatenation') # no spaces between words
print("Message" + "with" + "concatenation") # no spaces between words
4 changes: 2 additions & 2 deletions 1_beginner/chapter1/practice/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# fix the style in this file so that it runs properly
# and there are comments explaining the program

'''
"""
print("Hello World!")

print("This is a Python program")
Expand All @@ -12,4 +12,4 @@
input("Enter your age: ")

print("Your age is " + age)
'''
"""
2 changes: 1 addition & 1 deletion 1_beginner/chapter1/solutions/hello_world_again.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Hello World Again
# Print "Hello World" to the console
print('Hello World')
print("Hello World")
10 changes: 5 additions & 5 deletions 1_beginner/chapter1/solutions/my_first_chapter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# My First Chapter
# Print "My first chapter" and "Good morning!"
# Then print 3 other messages of your choice to the console
print('My first chapter')
print('Good morning!')
print('This is a message')
print('This is another message')
print('One more message!')
print("My first chapter")
print("Good morning!")
print("This is a message")
print("This is another message")
print("One more message!")
4 changes: 2 additions & 2 deletions 1_beginner/chapter2/examples/convert.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Converting to Different Data Types

x = '5'
y = '6'
x = "5"
y = "6"
sum = int(x) + int(y) # this is 11 because x and y were converted to integers
print(sum)

Expand Down
2 changes: 1 addition & 1 deletion 1_beginner/chapter2/examples/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# strings are a series of characters
# they are in single or double quotes
print("Jane")
print('Doe')
print("Doe")

# integers are whole numbers (positive, negative, and 0)
print(25)
Expand Down
4 changes: 2 additions & 2 deletions 1_beginner/chapter2/examples/string_or_number.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# String or Number?

# strings
x = '5'
y = '6'
x = "5"
y = "6"
print(x + y) # this 56 (concatenation)

# integers
Expand Down
2 changes: 1 addition & 1 deletion 1_beginner/chapter2/examples/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# use variables to store data
first_name = "Jane"
last_name = 'Doe'
last_name = "Doe"

age = 25

Expand Down
6 changes: 1 addition & 5 deletions 1_beginner/chapter2/solutions/favorite.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@
favorite_person = input("Who is your favorite person? ")

# Display output
print(
favorite_person + " bought you "
+ favorite_food + " and "
+ favorite_drink + "."
)
print(favorite_person + " bought you " + favorite_food + " and " + favorite_drink + ".")
2 changes: 1 addition & 1 deletion 1_beginner/chapter2/solutions/print_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

# strings
print("Tahiti, it's a magical place")
print('May the Force be with you')
print("May the Force be with you")
print("Hey guys")
5 changes: 1 addition & 4 deletions 1_beginner/chapter3/examples/logic_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
# or
was_computer_bought = True
was_bike_bought = False
print(
"Was a computer or bike bought? "
+ str(was_computer_bought or was_bike_bought)
)
print("Was a computer or bike bought? " + str(was_computer_bought or was_bike_bought))

# not
is_raining = False
Expand Down
9 changes: 3 additions & 6 deletions 1_beginner/chapter3/practice/change.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Write code that takes, as input, the number of dollars a person has
(a floating number), and outputs how much they have
in dollars, quarters, dimes, nickels and pennies.
Expand All @@ -15,13 +15,10 @@

Note: This is a challenge problem! Do not feel bad or disheartned if you can't
solve it. We will go over it next class.
'''
"""

CENTS_PER_DOLLAR = 100

num_cents = int(
float(input("How many dollars do you have: $"))
* CENTS_PER_DOLLAR
)
num_cents = int(float(input("How many dollars do you have: $")) * CENTS_PER_DOLLAR)

# What do you do next? Write code here
4 changes: 2 additions & 2 deletions 1_beginner/chapter3/practice/no_greater_than.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Create a program that takes a POSITIVE integer
as an input and checks if it is no greater than 100.
Print True if it is, and False if it isn't
Expand All @@ -7,6 +7,6 @@
LESS THAN OPERATORS (>, <, >=, or <=).
Find a way to do this problem only
using only the == operator and any math operators you want.
'''
"""

# write code here
9 changes: 3 additions & 6 deletions 1_beginner/chapter3/solutions/change.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Write code that takes, as input, the number of dollars a person has
(a floating number), and outputs how much they have
in dollars, quarters, dimes, nickels and pennies.
Expand All @@ -15,18 +15,15 @@

Note: This is a challenge problem! Do not feel bad or disheartned if you can't
solve it. We will go over it next class.
'''
"""

CENTS_PER_DOLLAR = 100
CENTS_PER_QUARTER = 25
CENTS_PER_DIME = 10
CENTS_PER_NICKEL = 5

# prompt user for dollars and convert it to cents
num_cents = int(
float(input("How many dollars do you have: $"))
* CENTS_PER_DOLLAR
)
num_cents = int(float(input("How many dollars do you have: $")) * CENTS_PER_DOLLAR)

# calculate change and display it
dollars = num_cents // CENTS_PER_DOLLAR
Expand Down
4 changes: 2 additions & 2 deletions 1_beginner/chapter3/solutions/cylinder_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# The formula for the volume of a cylinder is
# volume = pi * (radius ^ 2) * height
PI = 3.14
height = float(input('Height of cylinder: '))
radius = float(input('Radius of cylinder: '))
height = float(input("Height of cylinder: "))
radius = float(input("Radius of cylinder: "))
volume = PI * radius ** 2 * height
print("The volume of the cylinder is", volume)
2 changes: 1 addition & 1 deletion 1_beginner/chapter3/solutions/even.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
i = int(input("Enter an integer: "))

# Display output
is_even = (i % 2 == 0)
is_even = i % 2 == 0
print("Is this number even? " + str(is_even))
4 changes: 2 additions & 2 deletions 1_beginner/chapter3/solutions/no_greater_than.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Create a program that takes a POSITIVE integer
as an input and checks if it is no greater than 100.
Print True if it is, and False if it isn't
Expand All @@ -7,6 +7,6 @@
LESS THAN OPERATORS (>, <, >=, or <=).
Find a way to do this problem only
using only the == operator and any math operators you want.
'''
"""
x = int(input("Enter you number here. It must be positive: "))
print(x // 100 == 0)
4 changes: 2 additions & 2 deletions 1_beginner/chapter4/practice/four_numbers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Ask the user for 4 numbers.
Use only 3 if else blocks to find
the largest number. You may not use elifs.
Expand All @@ -10,6 +10,6 @@
print("nay")

This question is really tricky, and requires some ingenuity.
'''
"""

# Write code here
8 changes: 4 additions & 4 deletions 1_beginner/chapter4/practice/grade.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Grade
Write a program that asks the user to enter
the score for a student's test.
Expand All @@ -11,13 +11,13 @@
F: < 60

Print the letter grade that the test score receives.
'''
"""

# write code here

'''
"""
See if you can write the same program,
but without using >= anywhere.
'''
"""

# write code here
4 changes: 2 additions & 2 deletions 1_beginner/chapter4/practice/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
you start working.)
"""

'''
"""
if does_significant_work:
if makes_breakthrough:
is_nobel_prize_candidate = True
else:
is_nobel_prize_candidate = False
elif not does_significant_work:
is_nobel_prize_candidate = False
'''
"""
6 changes: 3 additions & 3 deletions 1_beginner/chapter4/practice/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
temp = int(input("Enter temperature: "))

if temp < 100: # 60-100 is hot
print('hot')
print("hot")
if temp <= 60: # 30-59 is normal
print('normal')
print("normal")
if temp < 30: # 0-29 is cold
print('cold')
print("cold")
4 changes: 2 additions & 2 deletions 1_beginner/chapter4/solutions/difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# greater than 17 print "Negative". Otherwise,
# print the result of 17 minus the given number.

x = float(input('Enter a number: '))
x = float(input("Enter a number: "))

if x > 17:
print('Negative')
print("Negative")
else:
print(17 - x)
4 changes: 2 additions & 2 deletions 1_beginner/chapter4/solutions/four_numbers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Ask the user for 4 numbers.
Use only 3 if else blocks to find
the largest number. You may not use elifs.
Expand All @@ -10,7 +10,7 @@
print("nay")

This question is really tricky, and requires some ingenuity.
'''
"""

a = float(input("Enter number 1: "))
b = float(input("Enter number 2: "))
Expand Down
8 changes: 4 additions & 4 deletions 1_beginner/chapter4/solutions/grade.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''
"""
Grade
Write a program that asks the user to enter
the score for a student's test.
Expand All @@ -11,7 +11,7 @@
F: < 60

Print the letter grade that the test score receives.
'''
"""

score = float(input("Enter test score: "))
if score >= 90:
Expand All @@ -25,10 +25,10 @@
else:
print("F")

'''
"""
See if you can write the same program,
but without using >= anywhere.
'''
"""

score = float(input("Enter test score: "))
if score < 60:
Expand Down
4 changes: 2 additions & 2 deletions 1_beginner/chapter4/solutions/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
drink = input("What drink would you like? ")

# discount of $1 if the user orders french toast and coffee
if food == 'french toast' and drink == 'coffee':
if food == "french toast" and drink == "coffee":
total_cost -= 1
# charge extra $1 if user orders chicken soup or apple juice
elif food == 'chicken soup' or drink == 'apple juice':
elif food == "chicken soup" or drink == "apple juice":
total_cost += 1

# display total
Expand Down
6 changes: 3 additions & 3 deletions 1_beginner/chapter4/solutions/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
temp = int(input("Enter temperature: "))

if 60 <= temp <= 100: # 60-100 is hot
print('hot')
print("hot")
if 30 <= temp < 60: # 30-59 is normal
print('normal')
print("normal")
if 0 <= temp < 30: # 0-29 is cold
print('cold')
print("cold")

# alternatively, you can also use elif
# if temp >= 60:
Expand Down
Loading