100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
UOA COMPSCI 101 BEST FULL NOTES | A+ | Cert. of Outstanding Achievement! $5.49   Add to cart

Class notes

UOA COMPSCI 101 BEST FULL NOTES | A+ | Cert. of Outstanding Achievement!

 5 views  0 purchase
  • Course
  • Institution

================CHEAPEST NOTES!!!================ ===============MINIMUM SALE PRICE=============== ************************ ONLY $5.49************************** My Grade Using These Notes: I got an A+ for COMPSCI 101 using these notes. I was among the top 10 achievers in a class of no less t...

[Show more]

Preview 4 out of 37  pages

  • January 30, 2023
  • 37
  • 2022/2023
  • Class notes
  • Mohammad ghafari; angela chang
  • All classes
avatar-seller
COMPSCI 101, Week 1, Lecture 2

When given a problem, we convert it into an algorithm. Break down problem into sequence of steps.

Algorithm is a finite set of steps that specifies a sequence of operations to be carried out in order to solve a specific
problem.

A computer program is an algorithm defined in a programming language.

Program is a sequence of instructions that performs a task.

Natural Langs. English, spoken by humans

Formal Langs. Math Notations, chemical structures, programming languages.

Programs are deterministic, results well defined, predictable



Programming languages

Machines only execute low-level languages, high-level languages (python) need to be processed to be executed
which takes some time, disadvantage for high-level langs.

Easier to program high-level, less time to write, shorter, easier to read, more likely to be correct, easy to maintain.
High-level langs. Are portable. Portable: Run on different kinds of computers with few, no modifications. Low-level
only can run on one type of computer, must be rewritten for other. Most programs written in high-level, low-level
only for specialised applications.

Two types of programs to process high-level langs. Interpreter and Compiler.

Interpreter reads program, executes. It does what program says. It processes it little at a time, alternate line read
and computations.




Compiler reads program, translates completely, then executes. High-level program (source code) gets complied into
object code/executable (low level). Then it can be executed repeatedly without further translation.




Python Interpreter

Source Code (Programs) are written in a programming language

Python interpreter translates and executes source code, into machine-code called Bytecode

, Variables

Any name works with some restrictions (not function name, no number first, no operator, no spaces)

Store only one variable at a time

Can be assigned to values. (=)

Cannot be any keyword

and elif import raise as else in return assert except is try break finally lambda

while class for nonlocal with continue from not yield def global or del if pass



Python is case sensitive, use lowercase for variables

Pythons style guide, conventions etc



Four basic types of info

Integer

Floating point

String

Boolean

Integer can be + 0 or -, no decimal

Floating point numbers have decimal point. Can be + 0 –

Left handside is always a variable, right hand side is value, expression

The right hand side of an assignment operator (=) is always computed first and then is assigned to the

Left hand side



Math operators

Add +

Subtract –

Multiply *

Divide /

Exponentiation/power of **

Precedence of Operators is

()

**

*, /, //, %

,+, -

For operators with same precedence, calculations are done left to right.

Division operations (/) results are always given as floating points e.g. 3/2 = 1.5, 6/2 = 3.0

An expression/variable can be used anywhere a single value can be used

String

String is a collection of characters delimited by ‘ or “

Print function

Print() uses brackets

When print prints the values in the brackets a line break is added.

So any further printing will be shown on the next line.

If no argument is given with print e.g. print(), This prints a blank line

Can be used to print more than one value/variable on a single line

Each value to be printed is separated by a comma.

e.g. print(1,’Hello’,’World’) 1 Hello World

print(‘The final results are:’,56,’and’,44) The final results are: 56 and 44

The default separator between different values to be printed is a single space.

Print(‘Final amount is $’, 100) Final amount is $ 100 (unnecessary space)

To change the default separator we provide an optional last argument to the print function

sep=’[your choice of separator]’ with double or single quotes

Eg

Print(‘Hello’, ‘World’, sep=’*’ Hello*World

So we can fix $ 100 so

Print(‘Final amount is $’, 100,sep=””) Final amount is $100,



end

, COMSCI 101, Week 1, Lecture 3

Literals

Literals are values that can be stored in program memory

Eg.

20, string

Year=2022

Year is variable and 2022 is literal

Variables can be assigned to and literal value or an expression. Variables refer to a single piece of info

Expressions

Made up of literal values and variables, expressions always evauluate to a single value. Right hand side of (=) is
expression.

Docstrings

Special string used to provide documentation.

3 consecutive quotes are used to surround docstring. In the format:

“””

Docstring

“””

Interpreter ignores docstring

Docstring gives author info and program description.

Program must have docstring

Too much info should not be provided, only general info

EVERY PROGRAMMING ASSIGNMENT MUST HAVE DOCSTRING, UNLESS TOLD OTHERWISE

Notes

After # to the end of the line is considered a note/comment, will not be read by interpreter

Only add when necessary, when code is difficult to comprehend.

Better than comments is to use descriptive variable names like this:

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller mightymihir100. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $5.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

78600 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$5.49
  • (0)
  Add to cart