{"base":{"id":"cs8-22","subject":"Programming","title":"Data types and constants","scene":"pycode","steps":[{"mode":"types","eyebrow":"Data types","title":"Number, text or True/False?","body":"Every value has a data type: int (whole number), float (decimal), str (text) or bool (True/False). The type decides what you can do with it. Go through the values.","actions":[{"id":"next","label":"Show one more value"},{"id":"reveal","label":"Show all types"}]},{"mode":"typed","eyebrow":"Choosing types","title":"Data for a quiz","body":"A quiz stores a name, a score and whether the answer was correct. Each needs the right type. Step through and watch the variables.","actions":[{"id":"step","label":"Run one line"},{"id":"run","label":"Run it all"}]},{"mode":"const","eyebrow":"Constants","title":"A name for a fixed value","body":"A constant is a named value that stays the same while the program runs, like a minimum age. Python writes constants in capitals. Change the age, then change the rule.","controls":[{"id":"age","label":"Player's age","min":5,"max":15,"step":1,"value":9}],"actions":[{"id":"change","label":"Change MIN_AGE to 10"}]},{"mode":"quiz","eyebrow":"Check yourself","title":"Pick the type","body":"A running app stores how far you ran, such as 3.75 km.","question":"Which data type fits best?","options":["int","float","bool"],"answer":1,"right":"Correct. 3.75 has a decimal part, so it's a float.","wrong":"Not quite. Does the value have a decimal point?","look":"types"}],"more":[{"type":"cards","id":"ideas","eyebrow":"Popular idea vs science","title":"Common mix-ups","items":[{"tag":"Popular idea","title":"\"\"42\" and 42 are the same.\"","body":"\"42\" in quotes is a string (text). \"42\" + \"1\" gives \"421\", but 42 + 1 gives 43."},{"tag":"Popular idea","title":"\"Typed input is already a number.\"","body":"input() always gives a string. Use int() or float() to turn it into a number."},{"tag":"Popular idea","title":"\"A constant is just any variable.\"","body":"A constant is meant never to change while the program runs; capitals tell programmers to leave it alone."}]},{"type":"cards","id":"table","eyebrow":"The four types","title":"Types at a glance","items":[{"tag":"int","title":"Whole numbers","body":"42, −7, 0. For counts, scores and ages."},{"tag":"float","title":"Decimals","body":"3.5, 1.62. For measurements and prices."},{"tag":"str","title":"Text","body":"\"Mia\", \"Hello!\". Always inside quote marks."},{"tag":"bool","title":"True or False","body":"For yes/no flags, like correct = True."}]},{"type":"cards","id":"code","eyebrow":"Code","title":"Using types and a constant","items":[{"tag":"Quiz data","title":"Types in action","body":"name = \"Mia\"       # str\nscore = 0          # int\ncorrect = True     # bool\nif correct:\n    score = score + 10\nprint(name, score)","code":true},{"tag":"Constant","title":"One place to change","body":"MIN_AGE = 8\nif age >= MIN_AGE:\n    print(\"Welcome!\")\nelse:\n    print(\"You must be\", MIN_AGE)","code":true}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Type hunt","items":[{"title":"Types around you","time":"15 minutes","need":["Paper and a pen"],"steps":["List 12 pieces of data from daily life: your age, your name, today's temperature, 'is it raining?', a bus number, a price…","Write the best type next to each: int, float, str or bool.","Find one that could be two types (a phone number: int or str?) and decide which is better.","Think of one rule that would make a good constant, like the number of players."],"why":"Phone numbers are best as strings: you never do maths with them and they can start with 0.","safety":"No safety risks."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Six more questions","questions":[{"question":"Which type is True?","options":["bool","str","int"],"answer":0,"right":"Correct. True and False are Boolean values.","wrong":"Not quite. Only two possible values."},{"question":"Which type is \"Hello\"?","options":["float","bool","str"],"answer":2,"right":"Correct. Text in quotes is a string.","wrong":"Not quite. Look at the quote marks."},{"question":"What is 7 + 3 in Python?","options":["73","10","an error"],"answer":1,"right":"Correct. Both are ints, so they are added.","wrong":"Not quite. Are they numbers or text?"},{"question":"What is \"7\" + \"3\" in Python?","options":["10","\"73\"","21"],"answer":1,"right":"Correct. Strings are joined together.","wrong":"Not quite. Look at the quote marks."},{"question":"Which type suits a player's score of 250?","options":["float","str","int"],"answer":2,"right":"Correct. A whole number count.","wrong":"Not quite. Is there a decimal part?"},{"question":"Why use a constant MAX_LIVES = 3 instead of typing 3 everywhere?","options":["It explains the number and changes in one place","It runs faster","It uses less electricity"],"answer":0,"right":"Correct. Clearer and easier to update.","wrong":"Not quite. What if the rule changes?"}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can explain…","items":["the four data types int, float, str and bool","how to choose a type for a piece of data","why \"42\" and 42 behave differently","why input() needs int() or float()","what a constant is and why it helps"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"data type","meaning":"The kind of value: int, float, str or bool."},{"word":"integer (int)","meaning":"A whole number."},{"word":"real (float)","meaning":"A number with a decimal part."},{"word":"string (str)","meaning":"Text, written in quote marks."},{"word":"Boolean (bool)","meaning":"True or False."},{"word":"constant","meaning":"A named value that doesn't change while the program runs."}]},{"type":"sources","id":"sources","title":"Sources","items":["Python documentation: Built-in types","PEP 8: naming constants"]}]},"overlay":null}