This lecture covers data types and selection statements in programming. It discusses common data types like integers, floats, strings and booleans. It also explains weak and strong typing, implicit and explicit type conversion. The lecture then covers selection statements like if-then, if-then-else and else-if statements which allow code to execute conditionally based on boolean expressions. It provides examples of comparison operators and logical operators used in boolean expressions.
This document provides an overview of the Python programming language. It discusses what Python is, its key features, who uses it, common applications, and how to download and install Python. It then covers Python syntax concepts like identifiers, keywords, multiline statements, docstrings, indentation, comments, and string formatting. The document also introduces Python data types like numbers, strings, lists, tuples, dictionaries, sets and how to work with them. It describes how to convert between number types and access/update strings and lists. Finally, it discusses Python development environments like Anaconda and Spyder.
This document discusses Python data types and variables. It covers numeric data types like int and float, as well as Boolean, string, and sequence data types. It also defines what a variable is, how to name variables, and how to print and update variable values. It introduces type casting and the input function for getting user input.
This document provides an overview of the Python programming language. It discusses what a program and programming language are, and then describes key features of Python like being simple, interactive, and object-oriented. It explains how to install Python and work in interactive and script modes. The document also covers Python concepts like variables, data types, functions, operators, and control structures like conditional statements and loops.
Data Type is a basic classification which identifies.docxtheodorelove43763
Data Type is a basic classification which identifies different types of data.Data Types helps in:Determining the possible values of a variablePossible operations which can be executed on the typeMeaning of the dataDifferent ways to store the data
Data Types are of different types:
Primitive data Types
Composite Data Types
*
Primitive data types are those data types which are not defined in terms of other data types.
Examples are:
Integer
Floating Point
Boolean
Character
*
NOTE: primitive here is not the same as how we use it when referring to the primitive types in Java even though they are mostly the same types. By primitive, we mean directly supported by hardware. Strings do not appear in this list because strings are rarely supported directly in hardware, instead they are stored as individual characters and linked together through some mechanism implemented by the programming language (usually as arrays of characters).
What about pointer types? You’ll notice that they do not appear above. Typically, pointers are just unsigned int values. But we treat pointers differently than ints because we do not permit pointer arithmetic (except in a few languages) and require dereferencing of some kind. Dereferencing may be directly supported in hardware by having indirect addressing modes.
Integers are used to hold integer values only.This is further categorized into:
byte
short
int
long
signed
Unsigned
Examples are:
unsigned int x = 21234;
unsigned int y = 31234;
unsigned int z;
z = x + y;
This data type contains decimal points.Examples are:
float f = 20.0 / 3.0;
Current standard version of floating-point
Single-precision (float)
One word: 1 sign bit, 23 bit fraction, 8 bit exponent
Positive range: 1.17549435 × 10-38 … 3.40282347 × 10+38
Double-precision (double)
Two words: 1 sign bit, 52 bit fraction, 11 bit exponent
Positive range: 2.2250738585072014 × 10-308 … 1.7976931348623157 × 10+308
*
Boolean Data type is used to store logical value.It can have either True or False value.It is a one bit representation0 represents false value1 represents true valueExample: Boolean a;
a=true;
Roman alphabet, punctuation, digits, and other symbols:Can encode within one byte (256 symbols)
In C:
char a_char = ’a’;
char newline_char = ’\n’;
char tab_char = ’\t’;
char backslash_char = ’\\’;
These data types are derived from more than one primitive data type.Examples are:
Arrays
Records
Structure
Union
Arrays are a finite sequence of variables of the same data type These are commonly implemented by the compiler generating array descriptors for each array
here we have
descriptors for
1-D and multi-D
arrays
*
Records are Varied aggregate of data elementsThe elements of a record are known as fields or membersRecords were introduced in COBOLThis data type is used in many languages.In Java, the functionality of records are achieved through the use of classes
Examples:
COBOL (nested structure.
The lecture recaps programming concepts covered so far like variables, data types, selection statements, and functions. It then presents a "Test Generator" case study to demonstrate designing, coding, and enhancing a program through multiple versions. The case study involves generating random math tests with addition or subtraction problems for students. Pseudocode is developed for each version to plan the program logic before coding.
Python is an open source programming language created by Guido van Rossum in 1991. It is named after the comedy group Monty Python and is based on the ABC language. Python supports both procedural and object-oriented programming and can be used for web development, data analysis, artificial intelligence, and more. It has a simple syntax and large standard library that make it easy to learn and use for various applications.
The document discusses various data types in Python including float, complex, bool, and str (string) types. It provides details on how each data type stores and represents values. For float, it notes they have a precision of 16 digits and can be represented exponentially. Complex numbers are written as x + yj. Bool only allows True or False values. Strings use Unicode encoding and can be delimited by either single or double quotes, using escape characters when needed. It also discusses accessing individual characters within a string using indexes.
This document provides an overview of the Python programming language. It discusses what Python is, its key features, who uses it, common applications, and how to download and install Python. It then covers Python syntax concepts like identifiers, keywords, multiline statements, docstrings, indentation, comments, and string formatting. The document also introduces Python data types like numbers, strings, lists, tuples, dictionaries, sets and how to work with them. It describes how to convert between number types and access/update strings and lists. Finally, it discusses Python development environments like Anaconda and Spyder.
This document discusses Python data types and variables. It covers numeric data types like int and float, as well as Boolean, string, and sequence data types. It also defines what a variable is, how to name variables, and how to print and update variable values. It introduces type casting and the input function for getting user input.
This document provides an overview of the Python programming language. It discusses what a program and programming language are, and then describes key features of Python like being simple, interactive, and object-oriented. It explains how to install Python and work in interactive and script modes. The document also covers Python concepts like variables, data types, functions, operators, and control structures like conditional statements and loops.
Data Type is a basic classification which identifies.docxtheodorelove43763
Data Type is a basic classification which identifies different types of data.Data Types helps in:Determining the possible values of a variablePossible operations which can be executed on the typeMeaning of the dataDifferent ways to store the data
Data Types are of different types:
Primitive data Types
Composite Data Types
*
Primitive data types are those data types which are not defined in terms of other data types.
Examples are:
Integer
Floating Point
Boolean
Character
*
NOTE: primitive here is not the same as how we use it when referring to the primitive types in Java even though they are mostly the same types. By primitive, we mean directly supported by hardware. Strings do not appear in this list because strings are rarely supported directly in hardware, instead they are stored as individual characters and linked together through some mechanism implemented by the programming language (usually as arrays of characters).
What about pointer types? You’ll notice that they do not appear above. Typically, pointers are just unsigned int values. But we treat pointers differently than ints because we do not permit pointer arithmetic (except in a few languages) and require dereferencing of some kind. Dereferencing may be directly supported in hardware by having indirect addressing modes.
Integers are used to hold integer values only.This is further categorized into:
byte
short
int
long
signed
Unsigned
Examples are:
unsigned int x = 21234;
unsigned int y = 31234;
unsigned int z;
z = x + y;
This data type contains decimal points.Examples are:
float f = 20.0 / 3.0;
Current standard version of floating-point
Single-precision (float)
One word: 1 sign bit, 23 bit fraction, 8 bit exponent
Positive range: 1.17549435 × 10-38 … 3.40282347 × 10+38
Double-precision (double)
Two words: 1 sign bit, 52 bit fraction, 11 bit exponent
Positive range: 2.2250738585072014 × 10-308 … 1.7976931348623157 × 10+308
*
Boolean Data type is used to store logical value.It can have either True or False value.It is a one bit representation0 represents false value1 represents true valueExample: Boolean a;
a=true;
Roman alphabet, punctuation, digits, and other symbols:Can encode within one byte (256 symbols)
In C:
char a_char = ’a’;
char newline_char = ’\n’;
char tab_char = ’\t’;
char backslash_char = ’\\’;
These data types are derived from more than one primitive data type.Examples are:
Arrays
Records
Structure
Union
Arrays are a finite sequence of variables of the same data type These are commonly implemented by the compiler generating array descriptors for each array
here we have
descriptors for
1-D and multi-D
arrays
*
Records are Varied aggregate of data elementsThe elements of a record are known as fields or membersRecords were introduced in COBOLThis data type is used in many languages.In Java, the functionality of records are achieved through the use of classes
Examples:
COBOL (nested structure.
The lecture recaps programming concepts covered so far like variables, data types, selection statements, and functions. It then presents a "Test Generator" case study to demonstrate designing, coding, and enhancing a program through multiple versions. The case study involves generating random math tests with addition or subtraction problems for students. Pseudocode is developed for each version to plan the program logic before coding.
Python is an open source programming language created by Guido van Rossum in 1991. It is named after the comedy group Monty Python and is based on the ABC language. Python supports both procedural and object-oriented programming and can be used for web development, data analysis, artificial intelligence, and more. It has a simple syntax and large standard library that make it easy to learn and use for various applications.
The document discusses various data types in Python including float, complex, bool, and str (string) types. It provides details on how each data type stores and represents values. For float, it notes they have a precision of 16 digits and can be represented exponentially. Complex numbers are written as x + yj. Bool only allows True or False values. Strings use Unicode encoding and can be delimited by either single or double quotes, using escape characters when needed. It also discusses accessing individual characters within a string using indexes.
The document provides an introduction to the Python programming language. It discusses that Python was created by Guido Van Rossum in 1991 and was named after the Monty Python comedy troupe. Python is an open source, interpreted language that can be used for both procedural and object-oriented programming. It has a simple syntax and supports features like graphical user interfaces, integration with other languages, and is used widely in applications like web development, artificial intelligence, and data science. The document also covers Python concepts like variables, data types, operators, input/output and comments.
The document provides information on fundamental C data types including bits, bytes, words, integers, floating point numbers, enumerated types, variables, type conversions, constants, and basic operators. It defines common data types like char, int, float, and double. It also covers typecasting, variable declaration, and basic arithmetic, logical, relational, and bitwise operators.
The document discusses algorithms and problem solving using Python. It defines an algorithm as a step-by-step procedure to get a desired output. Characteristics of algorithms include being unambiguous, having well-defined inputs and outputs, and terminating after a finite number of steps. The document provides an example algorithm to add two numbers and displays the result. It also discusses flowcharts, keywords, identifiers, data types like integers and strings, and data structures in Python like lists and dictionaries.
This document discusses Java data types and variables. It defines variables as containers that hold data values and notes there are three types: local, instance, and static. Local variables are declared within methods while instance variables are declared in a class but outside methods. Static variables can be accessed by the class name. The document also outlines Java's primitive data types like int and double, and non-primitive types like Strings and Arrays. It explains type casting between primitive types and differences between primitive and non-primitive data types.
This document provides an overview of the Java programming language, including its structure, keywords, data types, variables, operators, expressions, statements, and control flow structures. It discusses the structure of Java programs, including classes, packages, and the main method. It also covers Java APIs, documentation, errors, and examples of basic Java programs.
This document provides an overview of Java keywords, primitive data types, wrapper classes, variables, expressions, comments, casting, and overflow. It discusses the 50 Java keywords like abstract and boolean. It describes the 8 primitive types (boolean, char, byte, short, int, long, float, double), their ranges, and literals. It introduces the wrapper classes that correspond to each primitive type, like Integer for int. It also covers variables, expressions, single-line and multi-line comments, identity/widening/narrowing conversions during casting, and how overflow is handled for integer vs floating-point values.
Primitive data types in Objective-C include int, float, double, and char. Loops like for, while, and do-while are used to repeatedly execute code. Decision making statements include if-else, if-else if-else, switch, and the conditional operator. The document discusses these programming concepts and provides examples of defining and using variables of different data types, loops, and conditional statements in Objective-C code.
This document provides an overview of key concepts in Python including:
- Python is a dynamically typed language where variables are not explicitly defined and can change type.
- Names and identifiers in Python are case sensitive and follow specific conventions.
- Python uses indentation rather than brackets to define blocks of code.
- Core data types in Python include numeric, string, list, tuple, dictionary, set, boolean and file types. Each has specific characteristics and operators.
Python is a high-level, interpreted, interactive and object-oriented scripting language. It is designed to be highly readable using English keywords. Python is interpreted at runtime and does not require compilation. It supports both procedural and object-oriented programming. Python is beginner friendly and supports a wide range of applications. It is portable, extensible, and has a large standard library. Variables are dynamically typed and support integers, floating point numbers, complex numbers, strings, lists, tuples and dictionaries.
This document provides an overview of Python basics including:
1. Python can be used to develop various apps like GUI, web, games and more. It has limitations like not being a fast language and having few libraries.
2. The basic tokens in Python are keywords, identifiers, literals, operators, and punctuators. Common data types include numbers, strings, lists, tuples, and dictionaries.
3. Python supports various operators, conditional statements like if/else, loops like for and while, and functions like range() for iteration. Jump statements like break can alter normal program flow.
First in the series of slides for python programming, covering topics like programming language, python programming constructs, loops and control statements.
The document provides information on coding techniques and best practices for variable declarations and naming. It discusses data types, initializing variables, variable scope, naming conventions, and the Hungarian notation naming convention. The key points are:
- Variables should be declared close to where they are used and initialized immediately to avoid errors from unintended values.
- Variable names should be descriptive yet concise to indicate what they represent and avoid confusion. Naming conventions can help with readability and consistency.
- The Hungarian notation convention prefixes variable names with abbreviations to indicate their type, scope, and other properties to make their purpose clear at a glance.
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptxAhmedMehmood35
This lecture covers variables, data types, and type conversion in Java. It discusses that a variable stores a value in memory and has a type, name, and value. The lecture defines primitive data types like integers, floats, booleans, and characters. It explains type conversion between compatible types like widening and narrowing conversions. The scope of variables in Java is also covered, which includes the class and method level scopes. Operators, expressions, and constants are demonstrated. Finally, non-primitive data types in object-oriented programming are introduced.
C++ Basics introduction to typecasting Webinar Slides 1Ali Raza Jilani
The document provides information about algorithms and programming fundamentals in C++. It discusses what algorithms are, how to write them, and examples of algorithms to determine if a number is even or odd or if a student passed an exam. It also covers flowcharts, programming languages, data types, variables, operators, and comments in C++.
C# is an object-oriented programming language that is simple, modern and type-safe, derived from C and C++. It aims to combine the high productivity of Visual Basic with the power of C++. C# programs are typically written in .cs files and compiled to .exe files using the Visual Studio IDE and command line compiler. The language uses the .NET framework class library and supports value types that contain data and reference types that store references to objects.
This lecture covers data structures and iteration. It discusses arrays as ordered collections of values that allow items to be accessed by index. Python offers two array-like data structures: lists, which are mutable, and tuples, which are immutable. Loops allow code to repeatedly execute and come in two main types - while loops, which repeat while a condition is true, and for loops. Break and continue statements can be used in loops to exit or skip iterations under certain conditions.
Programming Fundamentals Lecture 3 covered data structures and iteration. Data structures allow storing multiple pieces of data in an organized way. Arrays are ordered collections of values that can be accessed by index. Python offers lists and tuples, where lists are mutable and tuples are immutable. Loops called iteration allow repeatedly running a block of code. While loops repeat while a condition is true. Break and continue can be used in loops to exit early or skip iterations conditionally.
More Related Content
Similar to ProgFund_Lecture_2_Data_Types_and_Selection-1.pdf
The document provides an introduction to the Python programming language. It discusses that Python was created by Guido Van Rossum in 1991 and was named after the Monty Python comedy troupe. Python is an open source, interpreted language that can be used for both procedural and object-oriented programming. It has a simple syntax and supports features like graphical user interfaces, integration with other languages, and is used widely in applications like web development, artificial intelligence, and data science. The document also covers Python concepts like variables, data types, operators, input/output and comments.
The document provides information on fundamental C data types including bits, bytes, words, integers, floating point numbers, enumerated types, variables, type conversions, constants, and basic operators. It defines common data types like char, int, float, and double. It also covers typecasting, variable declaration, and basic arithmetic, logical, relational, and bitwise operators.
The document discusses algorithms and problem solving using Python. It defines an algorithm as a step-by-step procedure to get a desired output. Characteristics of algorithms include being unambiguous, having well-defined inputs and outputs, and terminating after a finite number of steps. The document provides an example algorithm to add two numbers and displays the result. It also discusses flowcharts, keywords, identifiers, data types like integers and strings, and data structures in Python like lists and dictionaries.
This document discusses Java data types and variables. It defines variables as containers that hold data values and notes there are three types: local, instance, and static. Local variables are declared within methods while instance variables are declared in a class but outside methods. Static variables can be accessed by the class name. The document also outlines Java's primitive data types like int and double, and non-primitive types like Strings and Arrays. It explains type casting between primitive types and differences between primitive and non-primitive data types.
This document provides an overview of the Java programming language, including its structure, keywords, data types, variables, operators, expressions, statements, and control flow structures. It discusses the structure of Java programs, including classes, packages, and the main method. It also covers Java APIs, documentation, errors, and examples of basic Java programs.
This document provides an overview of Java keywords, primitive data types, wrapper classes, variables, expressions, comments, casting, and overflow. It discusses the 50 Java keywords like abstract and boolean. It describes the 8 primitive types (boolean, char, byte, short, int, long, float, double), their ranges, and literals. It introduces the wrapper classes that correspond to each primitive type, like Integer for int. It also covers variables, expressions, single-line and multi-line comments, identity/widening/narrowing conversions during casting, and how overflow is handled for integer vs floating-point values.
Primitive data types in Objective-C include int, float, double, and char. Loops like for, while, and do-while are used to repeatedly execute code. Decision making statements include if-else, if-else if-else, switch, and the conditional operator. The document discusses these programming concepts and provides examples of defining and using variables of different data types, loops, and conditional statements in Objective-C code.
This document provides an overview of key concepts in Python including:
- Python is a dynamically typed language where variables are not explicitly defined and can change type.
- Names and identifiers in Python are case sensitive and follow specific conventions.
- Python uses indentation rather than brackets to define blocks of code.
- Core data types in Python include numeric, string, list, tuple, dictionary, set, boolean and file types. Each has specific characteristics and operators.
Python is a high-level, interpreted, interactive and object-oriented scripting language. It is designed to be highly readable using English keywords. Python is interpreted at runtime and does not require compilation. It supports both procedural and object-oriented programming. Python is beginner friendly and supports a wide range of applications. It is portable, extensible, and has a large standard library. Variables are dynamically typed and support integers, floating point numbers, complex numbers, strings, lists, tuples and dictionaries.
This document provides an overview of Python basics including:
1. Python can be used to develop various apps like GUI, web, games and more. It has limitations like not being a fast language and having few libraries.
2. The basic tokens in Python are keywords, identifiers, literals, operators, and punctuators. Common data types include numbers, strings, lists, tuples, and dictionaries.
3. Python supports various operators, conditional statements like if/else, loops like for and while, and functions like range() for iteration. Jump statements like break can alter normal program flow.
First in the series of slides for python programming, covering topics like programming language, python programming constructs, loops and control statements.
The document provides information on coding techniques and best practices for variable declarations and naming. It discusses data types, initializing variables, variable scope, naming conventions, and the Hungarian notation naming convention. The key points are:
- Variables should be declared close to where they are used and initialized immediately to avoid errors from unintended values.
- Variable names should be descriptive yet concise to indicate what they represent and avoid confusion. Naming conventions can help with readability and consistency.
- The Hungarian notation convention prefixes variable names with abbreviations to indicate their type, scope, and other properties to make their purpose clear at a glance.
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptxAhmedMehmood35
This lecture covers variables, data types, and type conversion in Java. It discusses that a variable stores a value in memory and has a type, name, and value. The lecture defines primitive data types like integers, floats, booleans, and characters. It explains type conversion between compatible types like widening and narrowing conversions. The scope of variables in Java is also covered, which includes the class and method level scopes. Operators, expressions, and constants are demonstrated. Finally, non-primitive data types in object-oriented programming are introduced.
C++ Basics introduction to typecasting Webinar Slides 1Ali Raza Jilani
The document provides information about algorithms and programming fundamentals in C++. It discusses what algorithms are, how to write them, and examples of algorithms to determine if a number is even or odd or if a student passed an exam. It also covers flowcharts, programming languages, data types, variables, operators, and comments in C++.
C# is an object-oriented programming language that is simple, modern and type-safe, derived from C and C++. It aims to combine the high productivity of Visual Basic with the power of C++. C# programs are typically written in .cs files and compiled to .exe files using the Visual Studio IDE and command line compiler. The language uses the .NET framework class library and supports value types that contain data and reference types that store references to objects.
Similar to ProgFund_Lecture_2_Data_Types_and_Selection-1.pdf (20)
This lecture covers data structures and iteration. It discusses arrays as ordered collections of values that allow items to be accessed by index. Python offers two array-like data structures: lists, which are mutable, and tuples, which are immutable. Loops allow code to repeatedly execute and come in two main types - while loops, which repeat while a condition is true, and for loops. Break and continue statements can be used in loops to exit or skip iterations under certain conditions.
Programming Fundamentals Lecture 3 covered data structures and iteration. Data structures allow storing multiple pieces of data in an organized way. Arrays are ordered collections of values that can be accessed by index. Python offers lists and tuples, where lists are mutable and tuples are immutable. Loops called iteration allow repeatedly running a block of code. While loops repeat while a condition is true. Break and continue can be used in loops to exit early or skip iterations conditionally.
This lecture covers files and exception handling in Python. It discusses opening, reading from, and writing to files. The key steps are opening the file, using it (reading or writing data), and closing it. Exceptions allow programs to handle and respond to errors and unexpected situations gracefully using try/except blocks. The case study demonstrates generating math tests randomly and writing the output to a file rather than displaying it on screen. This improves the program by storing the results for later use.
This lecture covers functions and modules in Python. It discusses built-in functions, writing user-defined functions, function parameters and return values, and scope. It also discusses modules as a way to organize Python code and introduces some of Python's standard library modules like math and random. The key points are:
1) Functions allow for code reuse and abstraction by encapsulating repeatable processes. Built-in functions perform common tasks while user-defined functions can be created for custom tasks.
2) Functions are defined using def and have parameters to pass in inputs and return values to produce outputs. Variables inside functions have local scope while global variables can be accessed everywhere.
3) Modules help structure Python programs and provide
This document provides an introduction to C programming, including:
- A brief history of C and its advantages/disadvantages.
- An explanation of a simple "Hello World" program to demonstrate basic C syntax.
- Guidance on coding style best practices like indentation, spacing, and commenting code to improve readability and understanding.
This lecture introduces programming fundamentals and Python. It discusses what programming is, the process of translating source code into machine-readable instructions, and program design using pseudocode and flowcharts. Program design tools like pseudocode and flowcharts allow programmers to plan programs' logic and structure before writing the actual code. The lecture also provides an overview of Python syntax and variables.
This document provides an introduction to programming fundamentals and algorithms. It defines an algorithm as a well-ordered collection of unambiguous and effectively computable operations that produces a result and halts in a finite amount of time. The document discusses the history and purpose of programming, and defines computer science as the study of algorithms. It explains the three components that make up all algorithms: sequence, selection, and iteration. The document outlines the process for developing an algorithmic solution, including defining the problem, creating a high-level algorithm, defining inputs/outputs, testing the algorithm, and coding it.
Literature Review Basics and Understanding Reference Management.pptxDr Ramhari Poudyal
Three-day training on academic research focuses on analytical tools at United Technical College, supported by the University Grant Commission, Nepal. 24-26 May 2024
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSIJNSA Journal
The smart irrigation system represents an innovative approach to optimize water usage in agricultural and landscaping practices. The integration of cutting-edge technologies, including sensors, actuators, and data analysis, empowers this system to provide accurate monitoring and control of irrigation processes by leveraging real-time environmental conditions. The main objective of a smart irrigation system is to optimize water efficiency, minimize expenses, and foster the adoption of sustainable water management methods. This paper conducts a systematic risk assessment by exploring the key components/assets and their functionalities in the smart irrigation system. The crucial role of sensors in gathering data on soil moisture, weather patterns, and plant well-being is emphasized in this system. These sensors enable intelligent decision-making in irrigation scheduling and water distribution, leading to enhanced water efficiency and sustainable water management practices. Actuators enable automated control of irrigation devices, ensuring precise and targeted water delivery to plants. Additionally, the paper addresses the potential threat and vulnerabilities associated with smart irrigation systems. It discusses limitations of the system, such as power constraints and computational capabilities, and calculates the potential security risks. The paper suggests possible risk treatment methods for effective secure system operation. In conclusion, the paper emphasizes the significant benefits of implementing smart irrigation systems, including improved water conservation, increased crop yield, and reduced environmental impact. Additionally, based on the security analysis conducted, the paper recommends the implementation of countermeasures and security approaches to address vulnerabilities and ensure the integrity and reliability of the system. By incorporating these measures, smart irrigation technology can revolutionize water management practices in agriculture, promoting sustainability, resource efficiency, and safeguarding against potential security threats.
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...University of Maribor
Slides from talk presenting:
Aleš Zamuda: Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapter and Networking.
Presentation at IcETRAN 2024 session:
"Inter-Society Networking Panel GRSS/MTT-S/CIS
Panel Session: Promoting Connection and Cooperation"
IEEE Slovenia GRSS
IEEE Serbia and Montenegro MTT-S
IEEE Slovenia CIS
11TH INTERNATIONAL CONFERENCE ON ELECTRICAL, ELECTRONIC AND COMPUTING ENGINEERING
3-6 June 2024, Niš, Serbia
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTjpsjournal1
The rivalry between prominent international actors for dominance over Central Asia's hydrocarbon
reserves and the ancient silk trade route, along with China's diplomatic endeavours in the area, has been
referred to as the "New Great Game." This research centres on the power struggle, considering
geopolitical, geostrategic, and geoeconomic variables. Topics including trade, political hegemony, oil
politics, and conventional and nontraditional security are all explored and explained by the researcher.
Using Mackinder's Heartland, Spykman Rimland, and Hegemonic Stability theories, examines China's role
in Central Asia. This study adheres to the empirical epistemological method and has taken care of
objectivity. This study analyze primary and secondary research documents critically to elaborate role of
china’s geo economic outreach in central Asian countries and its future prospect. China is thriving in trade,
pipeline politics, and winning states, according to this study, thanks to important instruments like the
Shanghai Cooperation Organisation and the Belt and Road Economic Initiative. According to this study,
China is seeing significant success in commerce, pipeline politics, and gaining influence on other
governments. This success may be attributed to the effective utilisation of key tools such as the Shanghai
Cooperation Organisation and the Belt and Road Economic Initiative.
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsVictor Morales
K8sGPT is a tool that analyzes and diagnoses Kubernetes clusters. This presentation was used to share the requirements and dependencies to deploy K8sGPT in a local environment.
Low power architecture of logic gates using adiabatic techniquesnooriasukmaningtyas
The growing significance of portable systems to limit power consumption in ultra-large-scale-integration chips of very high density, has recently led to rapid and inventive progresses in low-power design. The most effective technique is adiabatic logic circuit design in energy-efficient hardware. This paper presents two adiabatic approaches for the design of low power circuits, modified positive feedback adiabatic logic (modified PFAL) and the other is direct current diode based positive feedback adiabatic logic (DC-DB PFAL). Logic gates are the preliminary components in any digital circuit design. By improving the performance of basic gates, one can improvise the whole system performance. In this paper proposed circuit design of the low power architecture of OR/NOR, AND/NAND, and XOR/XNOR gates are presented using the said approaches and their results are analyzed for powerdissipation, delay, power-delay-product and rise time and compared with the other adiabatic techniques along with the conventional complementary metal oxide semiconductor (CMOS) designs reported in the literature. It has been found that the designs with DC-DB PFAL technique outperform with the percentage improvement of 65% for NOR gate and 7% for NAND gate and 34% for XNOR gate over the modified PFAL techniques at 10 MHz respectively.
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesChristina Lin
Traditionally, dealing with real-time data pipelines has involved significant overhead, even for straightforward tasks like data transformation or masking. However, in this talk, we’ll venture into the dynamic realm of WebAssembly (WASM) and discover how it can revolutionize the creation of stateless streaming pipelines within a Kafka (Redpanda) broker. These pipelines are adept at managing low-latency, high-data-volume scenarios.
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELgerogepatton
As digital technology becomes more deeply embedded in power systems, protecting the communication
networks of Smart Grids (SG) has emerged as a critical concern. Distributed Network Protocol 3 (DNP3)
represents a multi-tiered application layer protocol extensively utilized in Supervisory Control and Data
Acquisition (SCADA)-based smart grids to facilitate real-time data gathering and control functionalities.
Robust Intrusion Detection Systems (IDS) are necessary for early threat detection and mitigation because
of the interconnection of these networks, which makes them vulnerable to a variety of cyberattacks. To
solve this issue, this paper develops a hybrid Deep Learning (DL) model specifically designed for intrusion
detection in smart grids. The proposed approach is a combination of the Convolutional Neural Network
(CNN) and the Long-Short-Term Memory algorithms (LSTM). We employed a recent intrusion detection
dataset (DNP3), which focuses on unauthorized commands and Denial of Service (DoS) cyberattacks, to
train and test our model. The results of our experiments show that our CNN-LSTM method is much better
at finding smart grid intrusions than other deep learning algorithms used for classification. In addition,
our proposed approach improves accuracy, precision, recall, and F1 score, achieving a high detection
accuracy rate of 99.50%.
2. This Lecture
• Data types
– Common data types: integer, float, string and boolean
– Weak/Strong typing and type conversion
– Implicit and explicit conversion
– Static and dynamic typing
– Numeric, string and boolean conversions
• Selection
– If-then, if-then-else and else-if statements
– Boolean expressions
– Comparison operators and logical operators
2
3. Textbook
• Starting Out with Python, 4th Edition (Global)
– Tony Gaddis
• Reading the chapter(s) is required
– Read the indicated chapter(s) before class
• This week covers the following textbook chapter(s):
– Chapter 3 – Decision Structures and Boolean Logic
– Note: You may also wish to revise parts of Chapter 2 regarding data types
3
5. Data Types
• Last week we introduced the concept of variables
– Assigning a name to data stored in memory for later use
• We also briefly mentioned data types – the “categories” of data
– Integers, floating point numbers (floats), strings…
– The difference can be subtle; 3.14 is a float, '3.14' is a string
– All data (and hence every variable) in a program has a data type
• The data type essentially tells the language/computer how to interpret the values
that are stored in memory
– It determines what can and cannot be done with the data,
e.g. Arithmetic works on integers and floats, but not strings
– Functions often require values of a certain data type,
e.g. round() needs a float and an integer: round(2.327, 2)
5
6. Data Types
• The most common data types are:
• Some languages divide numeric data types further
– Data types for very large numbers, e.g. “long” in Java, or numbers with large
fractional parts, e.g. “double” in Java
• Some languages, such as C, do not support strings
– Such languages typically have a “character” or “char” data type, representing a
single character. An “array” of multiple characters can be used to represent a string
Type Description Examples
integer (int) Whole numbers 2, -500, 4294967296
float (float) Numbers with a fractional part 3.14159, -0.3, 25.0
string (str) A sequence of characters 'Hello, World!', '25', ' '
boolean (bool) A true or false value True, False
6
7. “Weak” and “Strong” Typing
• Different languages take different approaches to whether data types can be
mixed and converted automatically
• “Weakly typed” languages focus on being convenient
– Generally achieved by making it easier to mix different data types together and
converting between them automatically wherever appropriate
• The programming language tries to work things out for you
• “Strongly typed” languages focus on being safe
– Generally achieved by limiting the ability to mix different data types together –
conversions must be done explicitly by the programmer
• The programmer must consider and convert types manually
• Languages allow and disallow things based on their design, often ending up
somewhere between weak and strong
7
8. Data Type Conversion and Coercion
• Some values can be converted between different data types
– e.g. 100 (int), 100.0 (float) and '100' or '100.0' (strings)
• All languages provide ways to convert between data types
– e.g. The int(), float() and str() functions in Python
– Some languages use “(typename) value”, e.g. (int) 3.14
– Conversion will fail (or give unexpected results) if it doesn’t make sense,
e.g. trying to convert a string of 'cat' to an int
– Some conversions may involve a loss of data, e.g. converting 3.14 to an int
• Many languages do implicit (automatic) conversion between compatible data
types as needed, where possible; This is known as coercion
– Integers are commonly coerced to floats, e.g. 5 + 2.5 would become 5.0 + 2.5
– Languages like PHP can coerce numeric strings, e.g. 1 + '2' + 3.4 = 6.4
8
9. • “Static typing” is when a language requires you to declare (and adhere to) the
data type of every variable you create. C and Java are statically typed
– Trying to assign a value of a different type will result in an error (or coercion)
– Helps program optimisation and to prevent type-related bugs
• “Dynamic typing” is when the data type of a variable is determined by the value
it currently refers to, which can change. Python and PHP are dynamically typed
– You do not “declare” a data type for the variable, you just assign a value to it
– Convenient, particularly in languages which coerce data types automatically
Static and Dynamic Typing
String value; // declare a string
value = 1; // assign int to string
Error: Incompatible types
Java value = 1 # int
1
value = 'Potato' # string
'Potato'
value = -2.74 # float
-2.74
Python
int value; // declare an int
value = 3.14; // assign float to int
3
C
9
total
HELLO, my name is…
10. Type Conversion Example – Numbers
• What is happening in these examples?
– In Java (and some other “strongly typed” languages), dividing an integer by another
integer results in an integer
• The result was truncated to 0, then stored as a float of 0.0
• No rounding was performed; It simply kept the integer portion only
– In Python (and other “weakly typed” languages), the result of dividing two integers is
automatically coerced to a float
10
int value1 = 15;
int value2 = 20;
float result = value1 / value2;
System.out.println(result);
0.0
Java value1 = 15
value2 = 20
result = value1 / value2
print(result)
0.75
Python
11. Type Conversion Example – Numbers
• In this version, we explicitly convert value_one to a float
– We use (float) to convert value_one, an integer, to a float – 15.0
• Java will coerce value_two to match, and give the result as a float
– In Java, the result of any arithmetic is “widened” to the more encompassing data
type; int < long < float < double… e.g.
• int / int = int
• float / float = float
11
int value_one = 15;
int value_two = 20;
float result = (float) value_one / value_two; // convert value1 to float
System.out.println(result);
0.75
Java
• float / int = float
• int / float = float
12. Type Conversion Example – String Concatenation
• What is happening in these examples?
– Both of them are trying to combine a string and a float
• In the first one, the error message says that concatenation can only be performed
between strings, not between a string and a float
• In the second one, the error message says that you cannot add a float and a string
together – that’s not how arithmetic works!
– The goal is the same in both – concatenating them together into a single string,
i.e. 'The total is 79.4' or '79.4 is the total'
• The solution to both is to convert total to a string: str(total)
12
total = 79.4
output = 'The total is ' + total
TypeError: can only concatenate str (not "float") to str
output = total + ' is the total'
TypeError: unsupported operand type(s) for +: 'float' and 'str'
Python
13. Type Conversion Example – String Concatenation
• In this version, we explicitly convert total to a string
– We use the str() function to convert total to a string
• Now that there are strings on both sides of the “+”, Python can determine that you want to
concatenate them and do so without any problems
• Reminder: The total variable still refers to a float of 79.4 – the str() function simply
produces a string version of the value – it does not change the variable itself
– Concatenating numbers and strings is an area that languages handle differently
• We’ll look at some examples on the next slide!
13
total = 79.4
output = 'The total is ' + str(total)
'The total is 79.4'
output = str(total) + ' is the total'
'79.4 is the total'
Python
14. – PHP avoids ambiguity by using
“.” for concatenation
– It can also detect variables
inside strings due to the “$” at
the start of variable names
Type Conversion Example – String Concatenation
– JavaScript always coerces both values
to strings and concatenate them
– Even if one of the strings contains a
number…
var num = 79.4;
alert(num + ' is the total')
'79.4 is the total'
var string_num = '25';
alert(num + string_num)
'79.425'
JavaScript $total = 79.4;
echo 'The total is ' . $total;
'The total is 79.4'
echo "$total is the total";
'79.4 is the total'
PHP
total = 79.4
print(total, 'is the total. The total is', total)
'79.4 is the total. The total is 79.4'
Python
– As covered last week, Python’s print() function offers yet another way of
combining strings and numbers…
14
15. Type Conversion Example – Boolean Values
• True and False are the only two boolean values, but values of other data types
can always be converted to a boolean value
– The bool() function converts a value to a boolean value
• The rule that most languages follow when converting to a boolean value is:
– Values equivalent to 0, or empty/blank values are considered False
– All other values are considered True
• As always, there can be subtle differences between languages…
e.g. '0' (a string of the “zero” character) is True in Python, but False in PHP
15
bool(0) # int of 0
False
bool(0.0) # float of 0.0
False
bool('') # empty string
False
bool([]) # an empty "list"
False
Python
bool(5) # positive int
True
bool(-245.271) # negative float
True
bool('False') # string of 'False'
True
bool('0') # string of 0
True
Python
16. Data Types / Type Conversion Summary
• While there are general concepts such as “weak” and “strong” typing, our
examples have demonstrated that…
– Almost every language handles things slightly differently!
– Regardless of what a language allows and supports, a good programmer should
always consider data types
• Know what type your data is, and how it can be used
• Learn how your language behaves when mixing/coercing types
• Failing to do so can result in bugs and security vulnerabilities
– Always test your code thoroughly to ensure it is working
• Particularly in weakly typed languages or ones you’re new to
• You won’t always receive an error message to let you know!
16
18. Selection
• When a program is run, it runs the statements in the source code from start to
end (unless it encounters an error)
– Certain statements allow for a choice between different blocks of code to run based
upon the result of checking for a specific condition
– These are known as selection statements
– In this example, the beeping noise only occurs if the timer value is 0
• We will examine the most common selection statement – “if-then” (aka just “if”)
– Can be extended upon with “else” and “else-if”
– Another selection statement, “switch”, is covered in Reading 2.4
If timer value is 0
Make beeping noise
Pseudocode
18
19. If-Then Statements
• An if-then statement will run a block of code only if a condition
(known as a “boolean expression”) evaluates to True
– Often used run certain code in response to user input
19
condition
True
False
only run if true
// tax free threshold check
int income;
printf("Enter income: ");
scanf("%d", &income);
if(income <= 18200)
{
printf("No tax for you!");
}
C
# tax free threshold check
income = int(input('Enter income: '))
if income <= 18200:
print('No tax for you!')
Python
20. If-Then Statements
• The structure of an if-then statement is largely the same in most languages,
although Python strives for readability and uses indentation
– Most languages:
if (<boolean expression>)
{
<code to run if True>
}
– Python:
if <boolean expression>:
<code to run if True>
20
Boolean expression
in parentheses
No parentheses, but
a colon at the end
True-code controlled by indentation
(4 spaces is the standard/default)
True-code enclosed by braces (curly brackets)
21. If-Then Statements
• There are some subtle nuances that you should be aware of…
(remember, we’re learning a concept, not a language)
– In languages that use braces (curly brackets), they are usually optional if only one
statement is to be run when the expression is true:
if (<boolean expression>)
<single statement to run if True>
<code to run regardless>
– Some languages use (or just allow) “endif” instead of braces:
if (<boolean expression>)
<code to run if True>
endif
21
22. Boolean Expressions & Comparison Operators
• Selection statements choose which code to run based upon the result of a
boolean expression – i.e. An expression that results in either True or False
• You can compare values and receive a True or False result by using a
comparison operator
– Many functions will return (result in) either True or False
– A non-boolean value can be coerced to either True or False
22
Comparison Operator Description Example Example Result
< Less than 7 < 2 False
<= Less than or equal to 5 <= 5 True
> Greater than 7 > 2 True
>= Greater than or equal to 7 >= 2 True
== Equal to 7 == 2 False
!= Not equal to 7 != 2 True
23. If-Then / Boolean Expression Examples
• Example 1: Comparing a numeric variable to a number:
– The input was converted to a float (using the float() function), so that the
“less than” comparison with a number works as intended
• Example 2: Using a function in a comparison:
– The built-in function len() returns the “number of items in an object” (in this case,
the number of characters in the string)
– We are using a “not equal to” comparison (!=) to check if the length of the string is
not equal to 5
23
Prompt user to type exactly 5 characters
If input length != 5
Show error message
Pseudocode
value = input('Enter exactly 5 characters: ')
if len(value) != 5:
print('Error: Incorrect number of characters.')
Python
Prompt user for a score out of 100
If score < 50
Show 'You fail!'
Pseudocode
score = float(input('Enter a score out of 100: '))
if score < 50:
print('You fail!')
Python
24. If-Then / Boolean Expression Examples
• Example 3: Using a boolean value returned from a function:
– .isupper() is a function that can only be used on strings, hence why it is
“attached to the end” of the string variable instead of being “wrapped around it”
– .isupper() returns True if all of the letters in the string are uppercase
• Example 4: Using a coerced boolean value:
– The value variable is coerced to a boolean value (see earlier slide):
An empty string ('') is False, anything else is True
24
Prompt user to type something in upper case
If user typed something in upper case
Congratulate user
Pseudocode
value = input('Enter something in upper case: ')
if value.isupper():
print('Congratulations on typing in upper case!')
Python
Prompt user to type anything
If user typed at least one character
Congratulate user
Pseudocode
value = input('Type anything!: ')
if value:
print('Well done!')
Python
25. Logical Operators
• Often you will need to make multiple comparisons in a boolean expression.
For this we use logical operators
– e.g. “is A and B True?”, or “is A or B True?”
– You may also find situations where you want to know if something is not true, i.e.
turn False into True and vice-versa
– For added readability, Python uses “and”, “or” and “not” for logical operators.
Many languages use “&&”, “||” and “!”
Logical Operator
Description Example
Example
Result
Python Alternate
and && True if both comparisons are true, otherwise false 1 < 5 and 4 == 6 False
or ||
True if either (or both) comparison is true,
false if they are both false
1 < 5 or 4 == 6 True
not ! Reverse/Flip true and false not (1 < 5) False
25
26. Logical Operator Truth Tables & Evaluation
• These “truth tables” illustrate which situations will result in which outcome when
using logical operators:
– An “and” will only be True if both expressions are True; If either (or both) are False,
the end result is False
– An “or” will be True if either (or both) expressions are True
• Logical operators are evaluated after evaluating the expressions on either side
of them to True/False
26
and True False
True True False
False False False
or True False
True True True
False True False
5 > 2
and
6 < 4
True
and
False
False
27. If-Then / Logical Operator Examples
• Example 1: Using “and”:
• Example 2: Using “or”:
– count() is a function that can be used on strings. It returns the number of
occurrences of a specified string within another string
• Example 3: Using “not”:
– .isalpha() is another function that can only be used on strings.
It returns True if all of the characters in the string are letters
27
Prompt user to a number between 5 and 15
If number is between 5 and 15
Congratulate user
Pseudocode
value = float(input('Enter a number between 5 and 15: '))
if value >= 5 and value <= 15:
print('Well done!')
Python
Prompt user to type at least 5 characters, no spaces
If input length < 5 or input contains spaces
Show 'Better luck next time!'
Pseudocode
value = input('Enter at least 5 characters, with no spaces: ')
if len(value) < 5 or value.count(' ') > 0:
print('Better luck next time!')
Python
Prompt user to type something that isn't a letter
If input is not a letter
Congratulate user
Pseudocode
value = input('Type something that is not a letter: ')
if not value.isalpha():
print('Well done!')
Python
28. Terrible Programmer Joke Break!
Mum said, “Please go to the market and get a bottle of milk,
and if they have eggs, get six.”
I came back with six bottles of milk.
Mum asked, “Why did you get six bottles of milk?!”
I replied, “Because they had eggs!”
28
29. Boolean Expression & Logical Operator Notes
• Each side of an “and” or an “or” must be a full comparison
– x == 0 or 1 ✘
• Boolean expressions can have multiple logical operators
– Order of operations: “not” first, then “and”, then “or”
– e.g. True or False and not True
– Parentheses can be used to alter order of operations
– e.g. (True or False) and not True (result is False)
– Even if not altering the order of operations, parentheses are a good way to make
your code clearer and more readable
x == 0 or x == 1 ✔
True or False and False (not evaluated)
True or False (and evaluated)
True (or evaluated)
31
30. If-Then-Else Statements
• An if-then-else statement runs one block of code if the boolean expression is
true, and another block if it is false – it is an extension of an if-then statement
32
# test result check
result = int(input('Enter your result: '))
if result >= 50:
print('You passed!')
else:
print('You failed!')
Python
condition
True False
only run if true only run if false
// checkbox check
if (document.form.checkbox.checked)
{
alert('Checkbox checked!')
}
else
{
alert('Checkbox not checked!')
}
JavaScript
31. If-Then-Else Statements
• An if-then-else statement uses the word “else” to indicate the block of code to be
run if the expression is False
– Everything we have discussed regarding if-then is relevant to if-then-else
(e.g. optional braces for single statements)
– Most languages:
33
if (<boolean expression>)
{
<code to run if True>
}
else
{
<code to run if False>
}
if <boolean expression>:
<code to run if True>
else:
<code to run if False>
– Python:
32. If-Then-Else Examples
– Prompt user to type their name
– If the name consists of only alphabetic
characters, print “Letters!”
– Otherwise print “Not all letters!”
– total_mark is an integer
– exam_passed is a boolean
– If both conditions are True (&& is and),
“You passed!” otherwise “You failed!”
• The else applies to all other outcomes
(one or both conditions False)
if (total_mark >= 50 && exam_passed)
{
System.out.println("You passed!");
}
else
{
System.out.println("You failed!");
}
Java
name = input('Name: ')
if name.isalpha():
print('Letters!')
else:
print('Not all letters!')
Python
34
33. Nested If-Then-Else Statements
• If-Then-Else statements can be “nested” within one another
– This allows you to test multiple conditions and run different code depending on which
ones are met, to implement whatever sequences of checks your program needs…
35
if <condition 1>:
<run if condition 1 True>
else:
if <condition 2>:
<run if condition 1 False
and condition 2 True>
else:
<run if both False>
Python if (<condition 1>)
{
<run if condition 1 True>
}
else
{
if (<condition 2>)
{
<run if condition 1 False
and condition 2 True>
}
else
{
<run if both False>
}
}
Most Languages
(This is just one example of how
selection statements can be nested:
Any desired flow of logic possible!)
34. Else-If
• If-Then can be also expanded by using an Else-If
– This allows you to “chain” selection statements together
– Only the code following the first condition that is True is run
36
condition
1
True
False
only run if
condition 1 true
condition
2
condition
3
False
False
True only run if
condition 3 true
True only run if
condition 2 true
only run if all
conditions false
• Languages use slightly different
else-if syntax:
– “else if”
• C, C++, Java, PHP, JavaScript…
– “elseif”
• PHP, Visual Basic…
– “elsif”
• Ada, Perl, Ruby…
– “elif”
• Python, Bash…
35. Else-If
• While the word used for else-if may differ between languages, it works the same
in pretty much all of them
– Remember, Python uses indentation instead of braces (“{}”)!
37
if <condition 1>:
<run if condition 1 True>
elif <condition 2>:
<run if condition 2 True>
elif <condition 3>:
<run if condition 3 True>
elif <condition 4>:
<run if condition 4 True>
else:
<run if all conditions False>
Python
if (<condition 1>) {
<run if condition 1 True>
}
else if (<condition 2>) {
<run if condition 2 True>
}
else if (<condition 3>) {
<run if condition 3 True>
}
else if (<condition 4>) {
<run if condition 4 True>
}
else {
<run if all conditions False>
}
Most Languages
Placing the opening brace after the
condition/else instead of on a separate
line is a common space-saving technique
36. Else-If Example
• Here’s an (overused) example for grade calculation:
# calculate grade from mark
mark = float(input('Enter your mark: '))
if mark >= 80:
grade = 'HD (High Distinction)'
elif mark >= 70:
grade = 'D (Distinction)'
elif mark >= 60:
grade = 'CR (Credit)'
elif mark >= 50:
grade = 'P (Pass)'
else:
grade = 'F (Fail)'
print('Your grade is:', grade)
Python
PROMPT for mark
IF mark >= 80
SET grade to 'HD'
ELSE IF mark >= 70
SET grade to 'D'
ELSE IF mark >= 60
SET grade to 'CR'
ELSE IF mark >= 50
SET grade to 'P'
ELSE
SET grade to 'F'
DISPLAY grade
Pseudocode
38
37. Else-If Example
• A flowchart for this program would look like:
39
mark
>= 80
True
False
Set grade to HD
mark
>= 70
mark
>= 50
False
False
True
Set grade to P
True
Set grade to D
Set grade to F
Prompt for
mark
mark
>= 60
True
Set grade to CR
False Display
grade
38. Conclusion
• It is important to be aware of data types, even in languages which make it
convenient to mix them implicitly
– Know how your language coerces things, what it allows and doesn’t allow, how to
convert things explicitly, etc…
• If-Then statements allow you to make a choice in your code
– Controlled by boolean expressions, which can involve comparison operators and
logical operators
– If-Then-Else to do one thing or another
– Else-If to chain multiple comparisons together
40