Skip to content

Commit f026bc3

Browse files
authored
Merge branch 'master' into kehao-addch9ex
2 parents 72abd30 + c81c656 commit f026bc3

File tree

44 files changed

+1327
-0
lines changed

Some content is hidden

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

44 files changed

+1327
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
Integer
3+
4+
Write a program that takes any number
5+
(decimals included) as input, and outputs
6+
whether or not it's an integer.
7+
"""
8+
9+
# Insert code here.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
Names
3+
4+
Write a program that asks a user
5+
for two names, and outputs True if
6+
the names are NOT the same.
7+
"""
8+
9+
# Insert code here.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Wizard
3+
4+
There are 3 criteria to determine whether
5+
you’re a wizard or not.
6+
7+
Define a variable called is_wizard and
8+
use logic operators to set it to the correct
9+
value based on the criteria.
10+
11+
Here are some example variable values and outputs.
12+
You'll need to figure out the order of logic operators
13+
needed to turn these inputs into these outputs! :)
14+
15+
Example variable values and output:
16+
17+
If you can fly, you’ve not a battled a dragon,
18+
and you’re alive, output “Wizard: True”
19+
20+
If you can fly, you’ve battled a dragon,
21+
and you’re not alive, output “Wizard: True”
22+
23+
If you can’t fly, you’ve battled a dragon,
24+
and you’re not alive, output “Wizard: False”
25+
26+
If you can’t fly, you’ve battled a dragon,
27+
and you’re alive, output “Wizard: True"
28+
29+
The initial variables are given, but you'll have
30+
to change the values to test your code.
31+
"""
32+
33+
can_fly = True
34+
battled_dragon = False
35+
is_alive = True
36+
37+
# Insert your code here.
38+
39+
# print("Wizard:", is_wizard)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Integer
3+
4+
Write a program that takes any number
5+
(decimals included) as input, and outputs
6+
whether or not it's an integer.
7+
"""
8+
9+
# Get input as a floating point
10+
x = float(input("Enter a number: "))
11+
12+
# Compare x to the integer version of itself
13+
is_integer = x == int(x)
14+
15+
print("Is integer? " + str(is_integer))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Names
3+
4+
Write a program that asks a user
5+
for two names, and outputs True if
6+
the names are NOT the same.
7+
"""
8+
9+
name1 = input("Person 1: ")
10+
name2 = input("Person 2: ")
11+
12+
# "False" if name1 and name2 are equal
13+
not_same = name1 != name2
14+
15+
print("Not the same?", not_same)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Wizard
3+
4+
There are 3 criteria to determine whether
5+
you’re a wizard or not.
6+
7+
Define a variable called is_wizard and
8+
use logic operators to set it to the correct
9+
value based on the criteria.
10+
11+
Here are some example variable values and outputs.
12+
You'll need to figure out the order of logic operators
13+
needed to turn these inputs into these outputs! :)
14+
15+
Example variable values and output:
16+
17+
If you can fly, you’ve not a battled a dragon,
18+
and you’re alive, output “Wizard: True”
19+
20+
If you can fly, you’ve battled a dragon,
21+
and you’re not alive, output “Wizard: True”
22+
23+
If you can’t fly, you’ve battled a dragon,
24+
and you’re not alive, output “Wizard: False”
25+
26+
If you can’t fly, you’ve battled a dragon,
27+
and you’re alive, output “Wizard: True"
28+
29+
The initial variables are given, but you'll have
30+
to change the values to test your code.
31+
"""
32+
33+
can_fly = True
34+
battled_dragon = False
35+
is_alive = True
36+
37+
is_wizard = can_fly or (battled_dragon and is_alive)
38+
39+
print("Wizard:", is_wizard)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
Multiply
3+
4+
Write a program that asks the user
5+
for 10 integers, multiplies them all
6+
together, and displays the product at
7+
the end.
8+
9+
Use a for loop!
10+
"""
11+
12+
# Insert your code here.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Multiply
3+
4+
Write a program that asks the user
5+
for 10 integers, multiplies them all
6+
together, and displays the product at
7+
the end.
8+
9+
Use a for loop!
10+
"""
11+
12+
# Initial value is 1
13+
product = 1
14+
15+
# Ask the user for 10 numbers and multiply.
16+
for i in range(10):
17+
product *= int(input("Enter a number: "))
18+
19+
print("The product is " + str(product))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Grades
3+
4+
Create a list called names and a list called grades.
5+
Ask the user to input a name, and then ask
6+
them to input the person's grade. Add the inputs
7+
to the corresponding lists. Use a for loop to ask
8+
for these inputs 5 times.
9+
10+
Display the info as "[name]: [grade]".
11+
12+
Example lists AFTER user input:
13+
names = ["John", "Belle", "Ria", "Steph", "Louis"]
14+
grades = [93, 85, 100, 82, 70]
15+
16+
Example output:
17+
John: 93
18+
Belle: 85
19+
etc.
20+
"""
21+
22+
# Insert your code here.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Indexing
3+
4+
1. Create a list with the following names:
5+
Mark
6+
Arya
7+
Paz
8+
Lulu
9+
Jon
10+
Robin
11+
2. Print the first element of the list.
12+
3. Print the 3rd-to last name ("Lulu") WITHOUT
13+
using people[3].
14+
4. Print the second element of the list.
15+
16+
Don't "hard-code" the answers.
17+
For example, don't write print("Mark").
18+
Instead, use list indexing to get the values
19+
from the list.
20+
"""
21+
22+
# Insert your code here.

0 commit comments

Comments
 (0)