Outline. transistors logic gates. on numbers on strings. writing numbers in words algorithm flowchart code

Similar documents
Place Value. Get in Place. WRITE how many tens and ones you see. Then WRITE the number they make. 5 3 = 53

Place Value I. Number Name Standard & Expanded

Instructional Tools Math Pack: Money n2y Unique Learning System

MATH MILESTONE # A1 NUMBERS & PLACE VALUES

How do you say that big number?

Transcriber(s): Baldev, Prashant Verifier(s): DeLeon, Christina Date Transcribed: Spring 2008 Page: 1 of 5

Human Rights begins with the end. His Body. His Penis. His Foreskin. Say No to Circumcision. His Whole Body will Thank you. 100%

Maths CAPS. Counting. Fill in the missing numbers: Counts forward and backward in 1s, 2s, 3s, 4s, 5s and 10s from any number between 0 and 200.

Number Sense 1 AP Book 3.1

a) 1/2 b) 3/7 c) 5/8 d) 4/10 e) 5/15 f) 2/4 a) two-fifths b) three-eighths c) one-tenth d) two-thirds a) 6/7 b) 7/10 c) 5/50 d) ½ e) 8/15 f) 3/4

NUMBERS & PLACE VALUES

Year 2 s Book of Helpful Hints

These tests contain questions ranging from Level 2 to Level 3. Children should have five seconds to answer questions 1 3 in each test,

Hexagon Puzzle. four. ten three. eighteen. twenty-one. six. fourteen. twenty. one hundred. seventeen. sixteen. one quarter. two.

Hundred Thousands. Practice to review I can read and write numbers through 999,999! Practice to remember HW 1.2A. Chapter 1 Place Value.

Naming Whole Numbers and Money

California 1 st Grade Standards / Excel Math Correlation by Lesson Number

Copyright Cengage Learning. All rights reserved.

Two-Digit Numbers. tens ones = tens ones = tens ones = 3 tens 5 ones = 35. tens ones = tens ones =

Learn your Fours. 1 Homeshcool

NS3 Part 1: BLM List. Workbook 3 - Number Sense, Part 1 1 BLACKLINE MASTERS

0:00:07.150,0:00: :00:08.880,0:00: this is common core state standards support video in mathematics

Unit 1: You and Your Money

Directive No 1/2004. Directive on License Fees for. Telecommunication and Radiocommunication. Equipments, Radio Frequency Spectrum,

Has difficulty in partitioning, for example, 208 into 190 and 18 and 31 into 20 and 11

Hinojosa Kinder Math Vocabulary Words. Topic 1. number. zero. one

Number Sense Workbook 5, Part 1

Logic diagram: a graphical representation of a circuit

Available online at ScienceDirect. Procedia Computer Science 89 (2016 )

What must be added to 60 to make one hundred? What is seventy minus forty?

Stage 2 PROMPT sheet. 2/3 Estimate numbers. 2/1 Know the 2, 3, 5, 10 times tables. 2/4 Order numbers. Count in 10s.

Stage 2 PROMPT sheet. 2/3 Estimate numbers. 2/1 Know the 2, 3, 5, 10 times tables. 2/4 Order numbers. 2/2 Place value

1. Copy and complete each number pattern. a b c. 51 kg 51,2kg 51,8kg d

Properties of Numbers

SAMPLE NINTH EDITION. Margaret L. Lial American River College. Stanley A. Salzman American River College

Learning Log Title: CHAPTER 1: INTRODUCTION AND REPRESENTATION. Date: Lesson: Chapter 1: Introduction and Representation

Working with Teens! CA Kindergarten Number Sense 1.2: Count, recognize, represent, name, and order a number of objects (up to 30).

v1.2 (2017/09/30) Tibor Tómács

Learn your Sixes. 1 Homeshcool.

Series. Student. Numbers. My name

Digital Logic Circuits

Using Place Value Cards

4 th Grade Math Notebook

PLACE VALUE. Edexcel GCSE Mathematics (Linear) 1MA0

Arithmetic Practice. Self-descriptive Numbers. Magic Squares. Magic 30. Totalines. continued. Addogons. Multogons. Arithmecuts. Jumblies.

Place Value. Review. Quiz FREE (100-1,000) Number Form Expanded Form Word Form Comparing & Ordering Rounding

Algebraic Expressions and Equations: Applications I: Translating Words to Mathematical Symbols *

SLCN Lesson Three Addition Algorithm

A Covering System with Minimum Modulus 42

b) 12 - = 6 d) 9 - = 3 e) 11 - = 8 f) 10 - = 7

What must be added to 30 to make one hundred? =

NCERT solution for Knowing our Numbers

MATH LESSON PLAN 2 ARITHMETIC & NUMBERS

Odd one out. Odd one out

Lesson 1. Numbers Large and Small. Let s Explore

Chapter 1: Digital logic

Copyright 2015 Edmentum - All rights reserved.

Whole Numbers. Lesson 1.1 Numbers to 10,000,000

Rounding inaccurately, particularly when decimals are involved, and having little sense of the size of the numbers involved

G RADE 1 MATHEMATICS. Blackline Masters

Free Math print & Go Pages and centers. Created by: The Curriculum Corner.

UNIT 1: NATURAL NUMBERS.

Edo. Edo fabrics by 6/5/12

Number Sense Workbook 4, Part 1

Reading and Understanding Whole Numbers

N1-1 Whole Numbers. Pre-requisites: None Estimated Time: 2 hours. Summary Learn Solve Revise Answers. Summary

Number Sense Workbook 6, Part 1

Numbers to digit revision

1 KNOWING OUR NUMBERS

My Body. How many? Look and count. seven. Ediciones SM

Number Sense 1 AP Book 4.1

3) Round 62,164 to the nearest ten thousand.

Whole Numbers. Practice 1 Numbers to 10,000, ,000 four hundred thousand

Answers 1) Answers 1) = 800 2) = 700 3) 1, = 80 4) = 4,000 5) = 800 6) = 1,500 7) 3, = 50 8) 1, = 20

PROGRAMA DE ENSEÑANZA BILINGÜE

Mathematics Third Practice Test A, B & C - Mental Maths. Mark schemes

Set A Pay Cheques & Stubs

1 Integers and powers

Hum, Michael, Michelle and Jeff, you can guess? I ll just guess anything, five I guess. One through infinity.

Numbers. Counting. Key Point. Key Point. Understand what a number is Count from 0 20 in numbers and words Count to 100

arvelous Patterning Activities Tens and Ones BINGO

First Grade Student Data Notebook

BCD Adder. Lecture 21 1

Series. Teacher. Numbers

Long vowels sound the same as the alphabet name. Aa Ee Ii Oo Uu. Learning English with Laughter Ltd. All Rights Reserved.

PRACTICAL ELECTRONICS TROUBLESHOOTING

Year 5 Mental Arithmetic Tests

b) three million, four hundred and forty-five thousand, eight hundred and eighty-five

Unit 7 Number Sense: Addition and Subtraction with Numbers to 100

2) 78,378 A) Hundreds B) Thousands C) Ten thousands D) Tens. 5) 2,694, 995 A) Millions B) Thousands C) Ten thousands D) Tens

Worksheet Set - Mastering Numeration 2

Just Kisses STAR MONOCHROMATIC. Designed by Ariga Mahmoudlou for RK Featuring Finished quilt measures: 64 x 64

Gates and Circuits 1

Name Date Class. Total (A) Total (B) Total (C) Test Total (A+B+C) R (0-9) I y (10-19) I G (20-25) Maths Basic Skills Week 1

Lesson 1: Place Value of Whole Numbers. Place Value, Value, and Reading Numbers in the Billions

A magician showed a magic trick where he picked one card from a standard deck. Determine What is the probability that the card will be a queen card?

#MakeItWithMarcusFabrics. Scrappier Dots. Fabric by Judie Rothermel. 57 x 68

Lecture #1. Course Overview

Counting Up The. holidays

Grade 6 Math. Numeracy: Text Chapter 2

Transcription:

Outline 1 Digital Systems transistors logic gates 2 Intrinsic Operations on numbers on strings 3 Dictionaries and Conditionals writing numbers in words algorithm flowchart code 4 Summary + Assignments MCS 260 Lecture 9 Introduction to Computer Science Jan Verschelde, 1 February 2016 Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 1 / 27

Digital Systems introduction to electronic circuits A computer is a synchronous binary digital system. digital: all information is discrete (not continuous) binary: only zero and one are used a binary digit is a bit synchronous: functioning is ruled by the system clock Basic elements to represent bits are switches that can be open (1) or closed (0). Transistors are electronic circuits to represent bits. Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 2 / 27

transistors and gates intrinsic operations 1 Digital Systems transistors logic gates 2 Intrinsic Operations on numbers on strings 3 Dictionaries and Conditionals writing numbers in words algorithm flowchart code 4 Summary + Assignments Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 3 / 27

Transistors electronic circuits to represent bits Transistors have three connections to the outside: 1 base: input voltage 2 collector: output voltage 3 emittor: to ground High Voltage: 1 Low Voltage: 0 B C E Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 4 / 27

transistors and gates intrinsic operations 1 Digital Systems transistors logic gates 2 Intrinsic Operations on numbers on strings 3 Dictionaries and Conditionals writing numbers in words algorithm flowchart code 4 Summary + Assignments Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 5 / 27

Logic Gates implement logic operators Logic gates are circuits that correspond to logic operators. Representations of NOT, AND, OR: NOT AND OR x NAND y = NOT (x AND y) x NOR y = NOT (x OR y) NAND NOR Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 6 / 27

A NOT Gate as realized by a transistor V in +V V out Input Voltage V in V in = low switch is open V out = +V V in = high switch is closed V out = low A NOT gate converts a low input voltage to high and a high input voltage to low. Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 7 / 27

A NAND Gate two transistors in series V 1 V 2 +V V out Input voltages V 1 and V 2 If either V 1 or V 2 is low: switch is open V out = +V If both V 1 and V 2 are high: switch is closed V out = low Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 8 / 27

A NOR Gate two transistors in parallel +V V out V 1 V 2 Input voltages V 1 and V 2 if either V 1 or V 2 is high closed switch V out = low; if both V 1 or V 2 are low open switch V out = +V. Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 9 / 27

intrinsic operations Intrinsic operations are those operations that belong to the standard library. For every variablex, the function id(x) returns the address ofx, type(x) returns the type ofx. Python has dynamic typing and garbage collection. Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 10 / 27

transistors and gates intrinsic operations 1 Digital Systems transistors logic gates 2 Intrinsic Operations on numbers on strings 3 Dictionaries and Conditionals writing numbers in words algorithm flowchart code 4 Summary + Assignments Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 11 / 27

conversions for numbers (built-in functions) function converts... int() string or number to integer float() string or number to float complex() string or number to complex number Examples: (j = 1, the imaginary unit) >>> complex(1) (1+0j) >>> complex( 89j ) 89j >>> _ + complex(3,4) (3+93j) Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 12 / 27

transistors and gates intrinsic operations 1 Digital Systems transistors logic gates 2 Intrinsic Operations on numbers on strings 3 Dictionaries and Conditionals writing numbers in words algorithm flowchart code 4 Summary + Assignments Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 13 / 27

intrinsic operations for strings Converting numbers to strings: >>> str(12*3) 36 Observe the use of right quotes: >>> str( 12*3 ) 12*3 >>> 12*3 12*3 Right quotes prevent the evaluation. With left quotes, as instr( 12*3 ), the expression12*3 is evaluated first before the conversion. Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 14 / 27

tests on strings built-in methods For a strings, we have the methods Examples: method returns True if... s.islower() s in lower case s.isupper() s in upper case s.istitle() s in title form s.isdigit() s contains only digits s.isalpha() s contains only letters s.isalnum() s contains only letters and digits x = hello x.islower() is True x.isalpha() is True x.isalnum() is True Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 15 / 27

classification of an input string Suppose we have a program alphatest.py to test if a given input is a number, is alphabetic, or is alphanumeric. $ python alphatest.py Give a number : 2341 "2341" consists of digits only $ python alphatest.py Give a number : hello "hello" is alphabetic $ python alphatest.py Give a number : hi5 "hi5" is alphanumeric $ python alphatest.py Give a number : hi 5 "hi 5" fails all tests Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 16 / 27

an if elif else to test an input string The code for alphatest.py is DATA = input( Give a number : ) SHOW = \" + DATA + \" if DATA.isalpha(): print(show + is alphabetic ) elif DATA.isdigit(): print(show + consist of digits only ) elif DATA.isalnum(): print(show + is alphanumeric ) else: print(show + fails all tests ) Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 17 / 27

transistors and gates intrinsic operations 1 Digital Systems transistors logic gates 2 Intrinsic Operations on numbers on strings 3 Dictionaries and Conditionals writing numbers in words algorithm flowchart code 4 Summary + Assignments Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 18 / 27

writing numbers in words applying dictionaries On a check, the amount is spelled out in words. Program specification: Input: n, a natural number < 1000. Output: a string expressing n in words. An example session withwrite_numbers.py: $ python write_numbers.py give a natural number : 125 125 is one hundred and twenty five Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 19 / 27

the dictionary: numbers spelled out in English For all n 20 and multiples of 10: DIC = { \ 0: zero, 1: one, 2: two, 3: three, \ 4: four, 5: five, 6: six, 7: seven, \ 8: eight, 9: nine, 10: ten, \ 11: eleven, 12: twelve, 13: thirteen, \ 14: fourteen, 15: fifteen, 16: sixteen, \ 17: seventeen, 19: nineteen, 20: twenty, \ 30: thirty, 40: forty, 50: fifty, \ 60: sixty, 70: seventy, 80: eighty, \ 90: ninety, 100: hundred \ } The dictionary lookupdic[n] handles special cases. Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 20 / 27

idea for the algorithm case analysis We distinguish three cases: 1 the trivial case: n = 0 This is the only case we writezero. 2 large numbers n 100 We start writing n/100hundred and then continue with 3 the rest: 0 < n < 100: 1 for n 20: dictionary lookup 2 for 20 < n < 100: compute r = n%10 and n r Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 21 / 27

transistors and gates intrinsic operations 1 Digital Systems transistors logic gates 2 Intrinsic Operations on numbers on strings 3 Dictionaries and Conditionals writing numbers in words algorithm flowchart code 4 Summary + Assignments Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 22 / 27

flowchart for write_numbers.py n= input( Enter your number : ) n = 0? True write zero False n > 100? True write d[ n 100 ]hundred n = 0? True n = n%100 False False n 20? True write d[n] False r = n%10 True r = 0? write d[n] False write d[n r] +d[r] Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 23 / 27

first half ofwrite_numbers.py The code starts with the dictionarydic =... DATA = input( give a natural number : ) NBR = int(data) OUTCOME = %d is % NBR if NBR == 0: OUTCOME += DIC[NBR] elif NBR >= 100: OUTCOME += DIC[NBR/100] + + DIC[100] NBR = NBR % 100 if NBR!= 0: OUTCOME += and This handles the first two cases of the algorithm. Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 24 / 27

second half ofwrite_numbers.py We continue with the rest 0 n < 100: if NBR > 0: # write zero only once if NBR <= 20: OUTCOME += DIC[NBR] else: REST = NBR % 10 if REST == 0: OUTCOME += DIC[NBR] else: OUTCOME += DIC[NBR-REST] + \ + DIC[REST] print(outcome) Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 25 / 27

Assignments 1 Draw all transistors needed to realize an OR gate and describe its working. 2 Construct truth tables for 1 (A OR B) OR NOT (A AND B) 2 NOT ((A OR C) OR B) OR (A AND C) 3 Draw the logic gates to realize the expressions of the previous exercise. 4 Letsecret be a secret number the user of a Python program has to guess. Give code for prompting the user for a guess and for printing feedback. 5 Write a script to usedbm to store the dictionaryd to spell numbers out in English. 6 Modify thewrite_numbers.py program so it uses thedbm file made in the previous exercise. Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 26 / 27

Reading Materials In this lecture we covered more of section 1.1 in Computer Science. An Overview pages 135-138 of Python Programming Intro to Computer Science (MCS 260) transistors and gates L-9 1 February 2016 27 / 27