Unit 3 Vocab
- Characters
- Strings
- Length
- Concatenation
- Traversing Strings
- Python if
- Elif
- Else Conditional
- Nested selection statements
- While loops with range
- With lists combining loops with conditionals to break
- Continue procedural abstraction
- python def procedures
- Parameters
- Return values
- Simulation
- Algorithm
Letters = ["a, b, c, d, e, f"]
print(Letters)
strings = ["apple, samsung, windows"]
print(strings)
string = "HelloWorld"
x = string[0:8]
y = string[0:5]
z = string[5:8]
print(x)
print(len(string))
print(y)
print(z)
string1 = ("Hello how are you?")
string2 = ("Im good!")
print(string1, string2)
greeting = "Hello World"
for o in greeting:
print(o)
x = 1
if x == 1:
print("x is 1")
price = 98343
if price > 100:
print("price is greater than 100")
elif price == 100:
print("price is 100")
elif price < 100:
print("price is less than 100")
hour = 19
if (hour < 18):
greeting = ("Good day")
else:
greeting = ("Good evening")
print (greeting)
hour = 19
if hour > 15:
if hour == 15:
print("it is 15 hours")
elif hour == 16:
print("it is 16 hours")
elif hour == 17:
print("it is 17 hours")
elif hour == 18:
print("it is 18 hours")
elif hour == 19:
print("it is 19 hours")
for num in range(1, 11):
print(num)
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for number in numbers:
if number == 7:
break
print(number)
def multiply(x, y):
return x * y
x = 3
y = 6
print(multiply(x, y))
def multiply(x, y):
return x * y
def add(x, y):
return x + y # in this case the parameter is x and y
def add(x, y):
return x + y
x = 3
y = 6
print(multiply(x, y)) # recalls a variable previously defined
def parse_input(input_string):
if input_string.strip() in {"1", "2", "3","4", "5", "6"}:
return int(input_string)
else:
print("Please enter a number from 1 to 6.")
raise SystemExit(1)
import random
def roll_dice(num_dice):
roll_results = []
for _ in range(num_dice):
roll = random.randint(1, 14)
roll_results.append(roll)
return roll_results
num_dice_input = input("How many dice do you want to roll? [1-6] ")
num_dice = parse_input(num_dice_input)
roll_results = roll_dice(num_dice)
print("you rolled:", roll_results)
print("What Grade Did You Get?")
grade = int(input("Enter Grade:"))
if grade >= 93:
print("Wow! Good job!")
if 70 <= grade < 93:
print("Nice!")
elif grade < 70:
print("Do Better")