Podcast
Questions and Answers
What will be the result of the expression int(3.9)
?
What will be the result of the expression int(3.9)
?
Which of the following statements about type conversion is true?
Which of the following statements about type conversion is true?
What is the output of the command print(3 + 2)
?
What is the output of the command print(3 + 2)
?
Which of the following expressions will yield a float as a result?
Which of the following expressions will yield a float as a result?
Signup and view all the answers
What does the print()
function do?
What does the print()
function do?
Signup and view all the answers
What type of error occurs when a program runs without crashing but produces an unexpected output?
What type of error occurs when a program runs without crashing but produces an unexpected output?
Signup and view all the answers
What is the result of executing the command 'print(3 + 'a')'?
What is the result of executing the command 'print(3 + 'a')'?
Signup and view all the answers
Which of the following is an example of a scalar object in Python?
Which of the following is an example of a scalar object in Python?
Signup and view all the answers
How can you check the type of an object in Python?
How can you check the type of an object in Python?
Signup and view all the answers
What happens when a program encounters a syntactic error?
What happens when a program encounters a syntactic error?
Signup and view all the answers
What is a non-scalar object in Python?
What is a non-scalar object in Python?
Signup and view all the answers
When does a static semantic error occur?
When does a static semantic error occur?
Signup and view all the answers
Which statement about objects in Python is true?
Which statement about objects in Python is true?
Signup and view all the answers
What is the first step in the process of finding a guess g for which g ∗ g is close to x?
What is the first step in the process of finding a guess g for which g ∗ g is close to x?
Signup and view all the answers
Which best describes an algorithm in the context of programming?
Which best describes an algorithm in the context of programming?
Signup and view all the answers
What type of computer stores and executes a sequence of instructions?
What type of computer stores and executes a sequence of instructions?
Signup and view all the answers
Which of the following best describes static semantics in programming languages?
Which of the following best describes static semantics in programming languages?
Signup and view all the answers
Which of the following statements about programming languages is true?
Which of the following statements about programming languages is true?
Signup and view all the answers
What result does the expression '3 + '5'' produce in a programming language?
What result does the expression '3 + '5'' produce in a programming language?
Signup and view all the answers
What is a basic primitive in programming, as described by Turing?
What is a basic primitive in programming, as described by Turing?
Signup and view all the answers
Which of the following provides a means of determining when to stop in a recipe-like process?
Which of the following provides a means of determining when to stop in a recipe-like process?
Signup and view all the answers
How do expressions in a programming language differ from basic primitives?
How do expressions in a programming language differ from basic primitives?
Signup and view all the answers
In programming, what does semantics refer to?
In programming, what does semantics refer to?
Signup and view all the answers
What is the result of the expression $3 * (2 + 5)$?
What is the result of the expression $3 * (2 + 5)$?
Signup and view all the answers
What does the expression $i , ext{mod} , j$ represent?
What does the expression $i , ext{mod} , j$ represent?
Signup and view all the answers
What will be the value of $a$ after executing the command $a, b = 3, 5$?
What will be the value of $a$ after executing the command $a, b = 3, 5$?
Signup and view all the answers
According to operator precedence, which operation will be executed first in the expression $3 + 5 * 2$?
According to operator precedence, which operation will be executed first in the expression $3 + 5 * 2$?
Signup and view all the answers
What does the syntax '# This is a comment' do in Python?
What does the syntax '# This is a comment' do in Python?
Signup and view all the answers
Which of the following correctly represents an assignment of multiple variables?
Which of the following correctly represents an assignment of multiple variables?
Signup and view all the answers
What will be the output if the value of pi is set to 3.14?
What will be the output if the value of pi is set to 3.14?
Signup and view all the answers
What is the outcome of the expression $3 ** 4$?
What is the outcome of the expression $3 ** 4$?
Signup and view all the answers
Study Notes
Course Details
- MUH101: Learn Python programming language
- All classes are face-to-face
- Communication is through Hacettepe University Digital Learning Platform (HADİ)
Grading
- 60% Midterm Exam (2 exams)
- 40% Final Exam (1 exam)
- Midterm format will be announced during the semester
Policy
- Collaboration on course material is encouraged
- Exams must be done individually, cheating results in -100, F3, and disciplinary action.
Programming Tips
- The course is fast-paced, practice early
- Do not skip lectures
- For beginners, practice is key.
- Download code before lecture and follow along.
- Don't be afraid to experiment with Python commands.
Recipes and Algorithms
- A recipe is a sequence of simple steps
- It defines the flow of control process and when each step is executed
- It determines when to stop
- An algorithm is similar to a recipe
- Example of Algorithm: 1 + 2 + 3 = an algorithm!
Computers as Machines
- Computers are machines that capture recipes as mechanical processes.
- Fixed program computer: A calculator, performs specific functions and has a fixed programming
- Stored program computer: Stores and executes instructions, more advanced than fixed program computers
Stored Program Computers
- Instructions are stored inside the computer.
- Instructions are built from a set of primitive instructions: arithmetic, logic, simple tests, and data movement.
- A special program called an interpreter executes instructions in order.
- Tests in the program alter the flow of control within the instruction sequence.
- The process stops when all instructions are executed.
Basic Primitives
- Turing proved that any computation can be done with 6 primitive instructions.
- Modern programming languages offer a broader and more convenient set of primitives.
- New primitives can be created.
- “Anything computable in one language is computable in any other programming language.” - Python, Java, C, Pascal, C++, and C# function similarly.
Creating Recipes
- Programming languages provide primitives: numbers, strings, simple operators
- Expressions are legal combinations of primitives within a programming language.
Aspects of Languages
- Syntax: Rules for valid strings (grammar)
- Static Semantics: Rules for which syntactically valid strings have meaningful interpretations
- Semantics: Meaning associated with syntactically correct strings
Where Things Go Wrong
- Syntactic errors: Common, easily caught, errors in the grammar of the code
- Static semantic errors: Some languages catch these before running. Can cause unpredictable behavior
- No static semantic errors, but unintended meaning: Can cause crashes, infinite loops, and unexpected results.
Examples
-
Syntactic error:
print(3.a)
,a = 5; 3a + 2
,a - 3'a'
, Python will throw a "SyntaxError" -
Static semantic error:
3 + 'a'
, Python will throw a "TypeError"
Python Programs
- Program is a sequence of definitions and commands
- Definitions are evaluated, commands are executed by the Python interpreter within a shell.
- Commands can be typed directly into a shell or stored in a file that is read into the interpreter.
Objects
- Objects have a type that defines what a program can do with them.
- Scalar objects: Cannot be subdivided. Examples include integers (int), real numbers (float), Boolean values (bool), and NoneType.
- Non-scalar objects: Have internal structure. Examples include Strings.
Scalar Objects
-
int
represents Integers. Example: 5 -
float
represents Real numbers. Example: 3.27 -
bool
represents Boolean values. Example: True, False -
NoneType
represents a special value calledNone
. -
type()
function can be used to determine the type of an object.
Non-Scalar Objects
-
Strings: Sequence of Characters, have internal structure. Example:
name = "burkay"
-
name[2:4]
would call out elements 2 and 3. - Object-oriented programming centers around using non-scalar objects.
Type Conversions (Cast)
- Convert objects from one type to another but not all types are convertible.
-
float(3)
Converts integer3
to float3.0
-
int(3.9)
Truncates float3.9
to integer3
Printing to Console
- Use
print()
command to display output from code to a user.
Expressions
- Combine objects & operators to create expressions.
- Expressions have values and types.
Operators on ints and floats
-
i+j
: Sum of integers i and j. Result is an integer if both are int, else is a float. -
i-j
: Difference -
i*j
: Product -
i/j
: Division, result is always a float -
i%j
: Remainder when i is divided by j -
i**j
: i raised to the power of j
Simple Operations
- Parentheses determine order of operations,
3 * (2 + 5)
- Order of operations without parentheses:
**
,*
,/
,+
and-
executed left to right.
Binding Variables and Values
-
=
assigns a value to a variable name. -
pi = 3.14159
bindspi
to3.14159
which is stored in memory. - Retrieve value associated with a variable by invoking its name, by typing
pi
.
Multiple Assignments
- Assign multiple values to multiple variables simultaneously.
-
a, b = 3, 5
Variable Naming
- Use clear, understandable names.
- Parentheses make the code more readable.
Comments
- Adds enrichment and documentation to code.
- Start a line with
#
to denote a comment. Python ignores commented lines.
Abstracting Expressions
- Why give names to values of expressions?
- It helps you organize and manage your code.
- It improves the readability and maintainability of your program.
- It allows you to reuse values and expressions without repeating them.
- Overall, it contributes to writing efficient and well-structured code.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Explore the fundamentals of Python programming in this interactive quiz designed for MUH101 students. Test your understanding of core concepts, algorithms, and programming tips to excel in your courses. Join us to enhance your skills and prepare for exams!