Skip to content
9 changes: 9 additions & 0 deletions 1_beginner/chapter3/practice/integer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Integer

Write a program that takes any number
(decimals included) as input, and outputs
whether or not it's an integer.
"""

# Insert code here.
9 changes: 9 additions & 0 deletions 1_beginner/chapter3/practice/names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Names

Write a program that asks a user
for two names, and outputs True if
the names are NOT the same.
"""

# Insert code here.
39 changes: 39 additions & 0 deletions 1_beginner/chapter3/practice/wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Wizard

There are 3 criteria to determine whether
you’re a wizard or not.

Define a variable called is_wizard and
use logic operators to set it to the correct
value based on the criteria.

Here are some example variable values and outputs.
You'll need to figure out the order of logic operators
needed to turn these inputs into these outputs! :)

Example variable values and output:

If you can fly, you’ve not a battled a dragon,
and you’re alive, output “Wizard: True”

If you can fly, you’ve battled a dragon,
and you’re not alive, output “Wizard: True”

If you can’t fly, you’ve battled a dragon,
and you’re not alive, output “Wizard: False”

If you can’t fly, you’ve battled a dragon,
and you’re alive, output “Wizard: True"

The initial variables are given, but you'll have
to change the values to test your code.
"""

can_fly = True
battled_dragon = False
is_alive = True

# Insert your code here.

# print("Wizard:", is_wizard)
15 changes: 15 additions & 0 deletions 1_beginner/chapter3/solutions/integer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Integer

Write a program that takes any number
(decimals included) as input, and outputs
whether or not it's an integer.
"""

# Get input as a floating point
x = float(input("Enter a number: "))

# Compare x to the integer version of itself
is_integer = x == int(x)

print("Is integer? " + str(is_integer))
15 changes: 15 additions & 0 deletions 1_beginner/chapter3/solutions/names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Names

Write a program that asks a user
for two names, and outputs True if
the names are NOT the same.
"""

name1 = input("Person 1: ")
name2 = input("Person 2: ")

# "False" if name1 and name2 are equal
not_same = name1 != name2

print("Not the same?", not_same)
39 changes: 39 additions & 0 deletions 1_beginner/chapter3/solutions/wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Wizard

There are 3 criteria to determine whether
you’re a wizard or not.

Define a variable called is_wizard and
use logic operators to set it to the correct
value based on the criteria.

Here are some example variable values and outputs.
You'll need to figure out the order of logic operators
needed to turn these inputs into these outputs! :)

Example variable values and output:

If you can fly, you’ve not a battled a dragon,
and you’re alive, output “Wizard: True”

If you can fly, you’ve battled a dragon,
and you’re not alive, output “Wizard: True”

If you can’t fly, you’ve battled a dragon,
and you’re not alive, output “Wizard: False”

If you can’t fly, you’ve battled a dragon,
and you’re alive, output “Wizard: True"

The initial variables are given, but you'll have
to change the values to test your code.
"""

can_fly = True
battled_dragon = False
is_alive = True

is_wizard = can_fly or (battled_dragon and is_alive)

print("Wizard:", is_wizard)
12 changes: 12 additions & 0 deletions 1_beginner/chapter5/practice/multiply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Multiply

Write a program that asks the user
for 10 integers, multiplies them all
together, and displays the product at
the end.

Use a for loop!
"""

# Insert your code here.
19 changes: 19 additions & 0 deletions 1_beginner/chapter5/solutions/multiply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Multiply

Write a program that asks the user
for 10 integers, multiplies them all
together, and displays the product at
the end.

Use a for loop!
"""

# Initial value is 1
product = 1

# Ask the user for 10 numbers and multiply.
for i in range(10):
product *= int(input("Enter a number: "))

print("The product is " + str(product))
22 changes: 22 additions & 0 deletions 1_beginner/chapter6/practice/grades.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Grades

Create a list called names and a list called grades.
Ask the user to input a name, and then ask
them to input the person's grade. Add the inputs
to the corresponding lists. Use a for loop to ask
for these inputs 5 times.

Display the info as "[name]: [grade]".

Example lists AFTER user input:
names = ["John", "Belle", "Ria", "Steph", "Louis"]
grades = [93, 85, 100, 82, 70]

Example output:
John: 93
Belle: 85
etc.
"""

# Insert your code here.
22 changes: 22 additions & 0 deletions 1_beginner/chapter6/practice/indexing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Indexing

1. Create a list with the following names:
Mark
Arya
Paz
Lulu
Jon
Robin
2. Print the first element of the list.
3. Print the 3rd-to last name ("Lulu") WITHOUT
using people[3].
4. Print the second element of the list.

Don't "hard-code" the answers.
For example, don't write print("Mark").
Instead, use list indexing to get the values
from the list.
"""

# Insert your code here.
32 changes: 32 additions & 0 deletions 1_beginner/chapter6/practice/manipulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Manipulation
# Modify the following code according to
# the instructions.

nums = []

"""
The following code adds the numbers 0, 10, ... 100
to the list nums, and displays this list.
First, make a copy of nums and store it in the varible more_nums.

Then, clear nums, and add the numbers
2, 7, 12, ... 72 to nums instead.
"""

for i in range(0, 101, 10):
nums.append(i)
print(nums)

"""
Write the code for the following actions:
Change the 1st element of more_nums to -100.
Change the 2nd element of nums to 0.
Remove the last element from more_nums.
Remove every element divisible by 3 from more_nums.
Insert a 21 after the 20 in more_nums (assume that
you DON'T know the index of 20 ahead of time).
Insert 15 0's in the 3rd-to-last position.
Sample list after insertions:
[..., 0, 0, ..., 0, 0, element, element]
Display nums and more_nums.
"""
17 changes: 17 additions & 0 deletions 1_beginner/chapter6/practice/names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Names

Make a list called people and fill it with
at least 6 names. Make another list and use
list slicing to fill it with every other name
from the original list, starting with the 1st name.
Print both lists.
"""

# Insert your code here.

"""
Use a for loop to ask the user to add 4 names
to the list. After you ask for each name, print
out the last 5 names of the list.
"""
94 changes: 94 additions & 0 deletions 1_beginner/chapter6/practice/restaurant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"""
Restaurant
Write a program that asks someone
what they want to order and give them
the total cost of their meal.

Each meal should have 3 categories
(ex. food, drinks, desserts), and the user
must order 1 item from each category.

Make sure to include a 7% sales tax
(multiply the total by 1.07), and
round the answer to 2 decimal places

The steps are outlined in the following code.
"""

"""
1. Store the menu in lists.
Each of the 3 categories should have an
items menu and a costs menu.

Example of the 6 lists you need to create:
foods, food_costs, drinks, drink_costs,
desserts, dessert_costs
"""

# Insert your lists here.

"""
2. Display the menu.
Iterate through the items and costs for each
category to do this.

Example output:
Welcome to my restaurant! Here's the menu:

Food:
Pancakes: $5
Waffles: $3
Toast: $100

Drinks:
Juice: $2
Water: $50
Tea: $1

Sugar:
Muffin: $4
Lollipop: $20
Brownie: $15
"""

# Insert the code for displaying the menu here.

"""
3. Ask the user to order.
This code should be in a loop. After you display the
user's total at the end, ask them if they want to
order again. If they say "no", the program should end.
Otherwise, you should take their order and display the
new total again.

As you take their order, check if what they ordered
is in the corresponding list for that category.
If it is, add the price of the item to the total.
Otherwise, display a warning message and add $1000 to the total.

Example order (using menu above):
What food would you like? pancakes
What drink would you like? water
What sugar item would you like? candy
You didn't order a proper sugary item! Adding $1000 to tab.
"""

# Insert the code that takes the user's order here.
# Make sure it's in a loop.

"""
4. Finalize the total.
Add a 7% sales tax to your sum, and
round this value to 2 decimal places.
Display the total.
"""

# Add the code to finalize and display the total here.

"""
5. As mentioned in Step 3, ask the user if they want
to order again. If they say "no", then stop the program.
Otherwise, let them order again.
"""

# Ask the user if they want to order again here.
32 changes: 32 additions & 0 deletions 1_beginner/chapter6/solutions/grades.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Grades

Create a list called names and a list called grades.
Ask the user to input a name, and then ask
them to input the person's grade. Add the inputs
to the corresponding lists. Use a for loop to ask
for these inputs 5 times.

Display the info as "[name]: [grade]".

Example lists AFTER user input:
names = ["John", "Belle", "Ria", "Steph", "Louis"]
grades = [93, 85, 100, 82, 70]

Example output:
John: 93
Belle: 85
etc.
"""

names = []
grades = []

# Collect inputs.
for i in range(5):
names.append(input("Enter a name: "))
grades.append(input("Enter their grade: "))

# Format output correctly.
for i in range(len(names)):
print(names[i] + ": " + grades[i])
Loading