week 4
This commit is contained in:
parent
d3e90b1de1
commit
988d387625
BIN
week 4/C-conds.pdf
Normal file
BIN
week 4/C-conds.pdf
Normal file
Binary file not shown.
1
week 4/First example Exercise.md
Normal file
1
week 4/First example Exercise.md
Normal file
@ -0,0 +1 @@
|
||||
files: Skill Check 1 - Sequence.doc
|
52
week 4/First example Exercise.py
Normal file
52
week 4/First example Exercise.py
Normal file
@ -0,0 +1,52 @@
|
||||
import os
|
||||
from time import sleep
|
||||
|
||||
def int_input(text):
|
||||
while True:
|
||||
try:
|
||||
user_input = int(input(text))
|
||||
return user_input
|
||||
except Exception:
|
||||
print("error")
|
||||
else:
|
||||
break
|
||||
|
||||
def screen_clear():
|
||||
# for mac and linux(here, os.name is 'posix')
|
||||
if os.name == 'posix':
|
||||
_ = os.system('clear')
|
||||
else:
|
||||
# for windows platfrom
|
||||
_ = os.system('cls')
|
||||
|
||||
adult_price=10
|
||||
kid_price=5
|
||||
|
||||
screen_clear()
|
||||
print("Welcome to Superslides inc.")
|
||||
|
||||
discount_days = {
|
||||
"saturday":True,
|
||||
"sat":True,
|
||||
"sunday":True,
|
||||
"sun":True
|
||||
}
|
||||
|
||||
in_service=True
|
||||
total = 0
|
||||
|
||||
while in_service:
|
||||
adults = int_input("Enter number adult customers: ")
|
||||
kids = int_input("Enter number children: ")
|
||||
price = adults*adult_price + kids*kid_price
|
||||
print("Order price:",price)
|
||||
total += price
|
||||
want_to_continue = input("Do you want to process another customer?: ").lower()
|
||||
screen_clear()
|
||||
match want_to_continue:
|
||||
case "yes":
|
||||
continue
|
||||
case "y":
|
||||
continue
|
||||
case _:
|
||||
in_service=False
|
BIN
week 4/L-loops.pdf
Normal file
BIN
week 4/L-loops.pdf
Normal file
Binary file not shown.
BIN
week 4/Multiply.vsd
Normal file
BIN
week 4/Multiply.vsd
Normal file
Binary file not shown.
1
week 4/Observation Task for iteration.md
Normal file
1
week 4/Observation Task for iteration.md
Normal file
@ -0,0 +1 @@
|
||||
files: Skill Check 3-Iteration _Loops.doc
|
59
week 4/Observation Task for iteration.py
Normal file
59
week 4/Observation Task for iteration.py
Normal file
@ -0,0 +1,59 @@
|
||||
import os
|
||||
from time import sleep
|
||||
|
||||
def int_input(text):
|
||||
while True:
|
||||
try:
|
||||
user_input = int(input(text))
|
||||
return user_input
|
||||
except Exception:
|
||||
print("error")
|
||||
else:
|
||||
break
|
||||
|
||||
def screen_clear():
|
||||
# for mac and linux(here, os.name is 'posix')
|
||||
if os.name == 'posix':
|
||||
_ = os.system('clear')
|
||||
else:
|
||||
# for windows platfrom
|
||||
_ = os.system('cls')
|
||||
|
||||
adult_price=10
|
||||
kid_price=5
|
||||
|
||||
screen_clear()
|
||||
print("Welcome to Superslides inc.")
|
||||
|
||||
discount_days = {
|
||||
"saturday":True,
|
||||
"sat":True,
|
||||
"sunday":True,
|
||||
"sun":True
|
||||
}
|
||||
|
||||
in_service=True
|
||||
total = 0
|
||||
|
||||
while in_service:
|
||||
adults = int_input("Enter number adult customers: ")
|
||||
kids = int_input("Enter number children: ")
|
||||
weekday = input("Day of visit: ")
|
||||
try:
|
||||
discount_days[weekday.lower()]
|
||||
price = adults*adult_price + kids*kid_price
|
||||
except Exception:
|
||||
price = (adults+kids)*kid_price
|
||||
print("Order price:",price)
|
||||
total += price
|
||||
want_to_continue = input("Do you want to process another customer?: ").lower()
|
||||
screen_clear()
|
||||
match want_to_continue:
|
||||
case "yes":
|
||||
continue
|
||||
case "y":
|
||||
continue
|
||||
case _:
|
||||
in_service=False
|
||||
print("Total revenue: "+total)
|
||||
|
7
week 4/Review of Concepts.md
Normal file
7
week 4/Review of Concepts.md
Normal file
@ -0,0 +1,7 @@
|
||||
Conditional Statements - Ifs
|
||||
|
||||
Loops - While loop / For loop
|
||||
|
||||
files:
|
||||
C-conds.pdf
|
||||
L-loops.pdf
|
1
week 4/Second example Exercise.md
Normal file
1
week 4/Second example Exercise.md
Normal file
@ -0,0 +1 @@
|
||||
files: Skill Check 2-Selectoin _.doc
|
57
week 4/Second example Exercise.py
Normal file
57
week 4/Second example Exercise.py
Normal file
@ -0,0 +1,57 @@
|
||||
import os
|
||||
from time import sleep
|
||||
|
||||
def int_input(text):
|
||||
while True:
|
||||
try:
|
||||
user_input = int(input(text))
|
||||
return user_input
|
||||
except Exception:
|
||||
print("error")
|
||||
else:
|
||||
break
|
||||
|
||||
def screen_clear():
|
||||
# for mac and linux(here, os.name is 'posix')
|
||||
if os.name == 'posix':
|
||||
_ = os.system('clear')
|
||||
else:
|
||||
# for windows platfrom
|
||||
_ = os.system('cls')
|
||||
|
||||
adult_price=10
|
||||
kid_price=5
|
||||
|
||||
screen_clear()
|
||||
print("Welcome to Superslides inc.")
|
||||
|
||||
discount_days = {
|
||||
"saturday":True,
|
||||
"sat":True,
|
||||
"sunday":True,
|
||||
"sun":True
|
||||
}
|
||||
|
||||
in_service=True
|
||||
total = 0
|
||||
|
||||
while in_service:
|
||||
adults = int_input("Enter number adult customers: ")
|
||||
kids = int_input("Enter number children: ")
|
||||
weekday = input("Day of visit: ")
|
||||
try:
|
||||
discount_days[weekday.lower()]
|
||||
price = adults*adult_price + kids*kid_price
|
||||
except Exception:
|
||||
price = (adults+kids)*kid_price
|
||||
print("Order price:",price)
|
||||
total += price
|
||||
want_to_continue = input("Do you want to process another customer?: ").lower()
|
||||
screen_clear()
|
||||
match want_to_continue:
|
||||
case "yes":
|
||||
continue
|
||||
case "y":
|
||||
continue
|
||||
case _:
|
||||
in_service=False
|
BIN
week 4/Skill Check 1 - Sequence.doc
Normal file
BIN
week 4/Skill Check 1 - Sequence.doc
Normal file
Binary file not shown.
BIN
week 4/Skill Check 2-Selectoin _.doc
Normal file
BIN
week 4/Skill Check 2-Selectoin _.doc
Normal file
Binary file not shown.
BIN
week 4/Skill Check 3-Iteration _Loops.doc
Normal file
BIN
week 4/Skill Check 3-Iteration _Loops.doc
Normal file
Binary file not shown.
BIN
week 4/Try-except block with error handling loop.JPG
Normal file
BIN
week 4/Try-except block with error handling loop.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 43 KiB |
3
week 4/Using conditionals and loops/Extras.md
Normal file
3
week 4/Using conditionals and loops/Extras.md
Normal file
@ -0,0 +1,3 @@
|
||||
Improving the program
|
||||
1. Adjustable difficulty. Some people are very good with numbers. They might find being tested on numbers from 1 to 10 rather boring. Some people are very bad with numbers, and might prefer easier questions. Obviously, it’s not too hard to change the program to use larger or smaller numbers. (Look at the program and make sure you can see how to do that.) It might be more interesting if the program became a little harder every time you get a question right, and a little easier every time you get one wrong. (For this to work well, you’d probably need to ask more than 10 questions.)
|
||||
2. Adjustable length. You might want a quick test, with only four questions. Or a long one, with 100 questions, to see how long you can stay awake. Make the program begin by asking how many questions you want, and then ask that many. To do this, you’ll need to know about things called “ranges”. They’re described in Sheet L (Loops).
|
1
week 4/Using conditionals and loops/Flowchart.md
Normal file
1
week 4/Using conditionals and loops/Flowchart.md
Normal file
@ -0,0 +1 @@
|
||||
files: Multiply.vsd
|
49
week 4/Using conditionals and loops/The problem.......md
Normal file
49
week 4/Using conditionals and loops/The problem.......md
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
|
||||
When you start to think about writing a program, it’s helpful to begin by thinking exactly what will usually happen when the program runs. Here is an example of a times-table testing program:
|
||||
|
||||
What’s 6 times 7?
|
||||
|
||||
*49*
|
||||
|
||||
*No, I’m afraid the answer is 42.*
|
||||
|
||||
*What’s 3 times 2?*
|
||||
|
||||
*6*
|
||||
|
||||
*That’s right well done.*
|
||||
|
||||
***And so on, with several more questions. . .***
|
||||
|
||||
*What’s 5 times 9?*
|
||||
|
||||
*45*
|
||||
|
||||
*That’s right well done.*
|
||||
|
||||
*I asked you 10 questions. You got 7 of them right.*
|
||||
|
||||
*Well done!*
|
||||
|
||||
So, here are some things we need to be able to make the computer do:
|
||||
|
||||
Choose numbers (at random, preferably)
|
||||
|
||||
Display a sum
|
||||
|
||||
Calculate the right answer
|
||||
|
||||
Get an answer from the person using the program
|
||||
|
||||
See whether it’s right or not
|
||||
|
||||
Display a final message saying how you’ve done
|
||||
|
||||
Display a “that’s right” or “that’s wrong” message
|
||||
|
||||
Keep count of how many questions were answered right
|
||||
|
||||
Ask a total of (say) 10 questions, and then stop
|
||||
|
||||
...........................That’s quite a lot of things to do!
|
Loading…
x
Reference in New Issue
Block a user