0% found this document useful (0 votes)
23 views53 pages

1.CS100 - 1 - First Week

The document serves as an introduction to Python programming for the CS100/CS101 courses at NITK for the Batch of 2027. It covers the capabilities of computers, problem-solving skills, and fundamental programming concepts, including flowcharts and algorithms. Additionally, it provides examples of computational problems, such as finding square roots and counting prime numbers, along with their respective solutions.

Uploaded by

hairpinbend0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views53 pages

1.CS100 - 1 - First Week

The document serves as an introduction to Python programming for the CS100/CS101 courses at NITK for the Batch of 2027. It covers the capabilities of computers, problem-solving skills, and fundamental programming concepts, including flowcharts and algorithms. Additionally, it provides examples of computational problems, such as finding square roots and counting prime numbers, along with their respective solutions.

Uploaded by

hairpinbend0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

Hello CDS,EEE, Batch of 2027

Welcome to NITK
CS100 / CS101
Python Programming,
Python Programming Lab
Outline
Where can you find computers?

What comes to your mind when someone says
“Computers”?
Where can you find computers?

Everywhere
Computer
Computer
What can a Computer do?

How does a computer work?
What can a Computer do?

Basic Arithmetic, Digital Logic

What can a Computer do?

Basic Arithmetic, Digital Logic
– + - * / % and or
What can a Computer do?

Basic Arithmetic, Digital Logic

Repeat these tasks (nearly) infinitely

What can a Computer do?

Basic Arithmetic, Digital Logic

Repeat these tasks (nearly) infinitely
– Think multiplication tables
What can a Computer do?

Basic Arithmetic, Digital Logic

Repeat these tasks (nearly) infinitely

Remember values of computations

What can a Computer do?

Basic Arithmetic, Digital Logic

Repeat these tasks (nearly) infinitely

Remember values of computations
– Memory
What can a Computer do?

Basic Arithmetic, Digital Logic

Repeat these tasks (nearly) infinitely

Remember values of computations

Computers only know what you tell them
– No intuition, No IQ, No problem solving skills, ...
CS100 and CS101 will teach you

Problem
Problem
Solving
Solving

Knowledge
Knowledge of
of Programming
Programming
Concepts
Concepts Skill
Skill
Problem Solving

Example problems.
Problem Solving

Find the next largest prime number.
Mersenne Prime

https://en.wikipedia.org/wiki/Mersenne_prime, https://en.wikipedia.org/wiki/Largest_known_prime_number, Mersenne Prime, Proth Prime


Mersenne Prime

The largest known prime number (as of Aug
2023) is 282,589,933 − 1, a number which has
24,862,048 digits when written in base 10.

It is a Mersenne Prime - M82,589,933

https://en.wikipedia.org/wiki/Mersenne_prime, https://en.wikipedia.org/wiki/Largest_known_prime_number, Mersenne Prime, Proth Prime


Problem Solving

Given an engineering challenge, produce a
working solution

Express the solution as a step-by-step
procedure a machine can understand
Problem Solving

Solution to a Computational problem
– Sequence of compute steps
Problem Solving

We’ll work out computations problems in the
first few classes
Knowledge Concepts, Programming Skill

Concepts in Computer Science
– Data, Instruction, Pseudo-code, Flowchart,
Algorithm, Program, ...

Knowledge Concepts, Programming Skill

Concepts in Computer Science
– Data, Instruction, Pseudo-code, Flowchart,
Algorithm, Program, ...

Programming skill
– Python
– Language features, capabilities, ...
CS100 – Class–2
Example Compute Problems

Find square root of a number

Find the number of Primes in (1, 100)
– 100 not inclusive

Find the number of Primes in range(start, end)
– end not inclusive
Square Root of a Number

Given Input:


Q: Find the square root of the input

Expected Output:

Square Root of a Number

Given Input: Number
– Eg. 16

Q: Find the square root of the input

Expected Output:
– 4
Steps to calculate root of a number
Calculate root of a number, n
1. Start with an arbitrary guess, g
2. Calculate g*g
3. If g*g is equal to n, we’re done! Output g
4. If not, use (g + n/g)/2 as the next guess.
5. Go to Step 2 and repeat
Calculate root of 16
g g*g n/g (g + n/g)/2
Calculate root of 16
g g*g n/g (g + n/g) / 2
500 25000 0.032 250.016
250.016 62508.000256 0.063995904 125.039997952
125.039997952 15635.001087869 0.127959055 62.583978504
62.583978504 3916.754365339 0.255656486 31.419817495
31.419817495 987.204931407 0.509232748 15.964525121
15.964525121 254.866062353 1.002222107 8.483373614
8.483373614 71.967627873 1.886042125 5.18470787
5.18470787 26.881195693 3.085998363 4.135353117
4.135353117 17.101145399 3.869077089 4.002215103
4.002215103 16.017725731 3.997786123 4.000000613
4.000000613 16.000004904 3.999999387 4
4 16 -- --
Calculate root of a number, n
1. Start with an arbitrary guess, g
2. Calculate g*g
3. If g*g is equal to n, we’re done! Output g
4. If not, use (g + n/g)/2 as the next guess.
5. Go to Step 2 and repeat Let
Letususrepresent
representthis
this
Computational
ComputationalSolution
Solution
in
inaastandard
standardform
form
Flowchart
Start

End
Flowchart

Input n
Flowchart

Calculate g*g
Flowchart

g*g False
Equals
n?

True
Calculate root of n - Flowchart
Start

1. Start with an arbitrary


guess, g
2. Calculate g*g
3. If g*g is equal to n,
we’re done! Output g
4. If not, use (g + n/g)/2 as
the next guess.
5. Go to Step 2 and repeat

End
Calculate root of n – Flowchart
Start
1. Start with an arbitrary
guess, g Input n

2. Calculate g*g
Pick an arbitrary Calculate
3. If g*g is equal to n, number, g (n + n/g)/2

we’re done! Output g


4. If not, use (g + n/g)/2 Calculate g*g
as the next guess.
5. Go to Step 2 and g*g
False
Equals
repeat n?

True
Output g End
Square Root of a Number

● Given
Given Input:
Input: Number
Number

● Given
GivenInput:
Input:Positive
Positivewhole
wholenumber
number
–– Eg. 16
–– Eg.
Eg.16
16 Eg. 16

Q:
Q:Find
Findthe
thesquare
squareroot
rootof
ofthe
theinput
input
Q:
Q: Find
Findthe
thesquare
square root
root of



of with
withananaccuracy
accuracyof
of+/-
+/-0.0001
0.0001
the
the input
input
● Accepted outputs:

Accepted outputs:

● Expected
ExpectedOutput:
Output: –– 4.0, 4.0001, 4.00005, ...
4.0, 4.0001, 4.00005, ...
–– 44 Outputs
OutputsNot
NotAccepted:
Accepted:4.1,
4.1,4.01,


4.01,
4.001
4.001
Homework

Draw a flowchart for your favorite activity this
week
Class 3
Check if 100 is a prime number

Input: 100

Q: Check if the given input is a prime number

Output: Yes / No
Draw the Flowchart
Check if 101 is a prime number

Input: 101

Q: Check if the given input is a prime number

Output: Yes / No
Draw the Flowchart
How many primes in (1, 100)

Inputs: 1, 100

Q: Count the number of prime numbers in the
given range

Output: 25
Count Primes in (1,100)
Count Primes in (1,100) – Flowchart
Extra Slides
Problem Solving

Given an engineering challenge, produce a
working solution; express the solution as
components of a machine
– Solution for a mechanical engineering challenge –
moving components (gears, pistons, ...), controllers
(electrical or microcontrollers)
Square Root of a Number

Given Input: Positive whole number
– Eg. 16

Q: Find the square root of the input with an accuracy of
+/- 0.0001

Accepted outputs:
– 4.0, 4.0001, 4.00005, ...

Outputs Not Accepted: 4.1, 4.01, 4.001

You might also like