Piyush Ranjan
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Operators --- title: Agenda description: duration: 300 card_type: cue_card --- ### Agenda 1. Operators 2. Arithmetic operators 3. Precedence of operators 4. Boolean operators 5. Comparison operators 6. Assignment operators 7. Logical Operators --- title: Operators description: duration: 2000 card_type: cue_card --- ## Operators - **Operators** are symbols of operation. - **Operands** are values on which operation is happening - Operation/Expression are combination of operands and operators - Operation/Expression gives a result after execution. <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/405/original/operators.png?1689918923" width=600 height=250> ## Arithmetic operators - operators such as `+`, `-`, `*`, `/`, `//`, `**`, `%` <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/407/original/arithmetic_op.png?1689919111" width=600 height=100> \ Code: ``` python= # Addition 10 + 3 ``` >Output: ``` 13 ``` Code: ``` python= # Subtraction 10 - 3 ``` >Output: ``` 7 ``` Code: ``` python= # Multiplication 10 * 3 ``` >Output: ``` 30 ``` - The return type of the division operator `/` is always a floating point object. Code: ``` python= # Division 10 / 3 ``` >Output: ``` 3.3333333333333335 ``` Code: ``` python= # float + float -> float 5.0 +5.0 ``` >Output: ``` 10.0 ``` ### Subset diagram of Number System - integers ⊂ floats ⊂ real numbers <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/411/original/number_system.png?1689919391" width=500 height=400> \ Python retains as much information as it can. - for `+`, `-`, `*` if one of the operand is float, then result is float. - for `/` the result is always float. --- title: Quiz-1 description: duration: 60 card_type: quiz_card --- # Question What would be the output of the following? ``` python x = 10 y = 2.5 print(x / y) ``` # Choices - [ ] 4 - [x] 4.0 - [ ] 4.5 --- title: Exponentiation, Floor Division & Modulas operators description: duration: 2000 card_type: cue_card --- ## Exponentiation operator (`**`) ```x**y``` = x $^ y$ Code: ``` python= 5 ** 2 ``` >Output: ``` 25 ``` Code: ``` python= 5 ** -1 ``` >Output: ``` 0.2 ``` Code: ``` python= 5 ** 0.5 # square root ``` >Output: ``` 2.23606797749979 ``` Code: ``` python= 5.0 ** 2 ``` >Output: ``` 25.0 ``` ## Floor Division operator (`//`) `x//y` = floor(x/y) ### Floor function - The floor() function gives the biggest integer less than the value. - On a number line, it gives the closest integer to the left of the value. - Example: - `floor(-0.67)` gives -1 - `floor(2.3)` gives 2 <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/412/original/floor1.png?1689920271" width=600 height=200> \ Code: ```python= 10//3 ``` >Output: ``` 3 ``` Code: ```python= -10//3 ``` >Output: ``` -4 ``` ## Modulus operator (`%`) `x % y` -> remainder of `x / y` - If `x` is **'+ve'** -> remainder of `x / y` - If `x` is **'-ve'** -> `y - (x % y)` Code: ``` python= 10 % 3 ``` >Output: ``` 1 ``` Code: ``` python= -10 % 3 ``` >Output: ``` 2 ``` --- title: Quiz-2 description: duration: 60 card_type: quiz_card --- # Question Predict the output. ``` python print(10**-1) ``` # Choices - [ ] 10 - [ ] 1/10 - [x] 0.1 --- title: Quiz-3 description: duration: 60 card_type: quiz_card --- # Question What would be the output of the following? ``` python 15//2 ``` # Choices - [ ] 7.5 - [x] 7 - [ ] 1 --- title: Precedence of operators description: duration: 360 card_type: cue_card --- ## Precedence of operators #### Question: Predict the ouptut ``` python 10-4*2 ``` **Ans:** 2 - Division and Multiplication have the same order of precedence. - Addition and Subtraction have the same order of precedence. - In case of encountering operators with same precedence, go from **left to right**. <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/415/original/bodmas.png?1689922896" width=600 height=300> #### Question: Predict the output ``` python 10-4*2+5-6/2 ``` **Ans:** 4.0 <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/416/original/question_bodmas.png?1689922995" width=600 height=350> <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/417/original/bodmas_question_2.png?1689923639" width=600 height=250> --- title: Quiz-4 description: duration: 60 card_type: quiz_card --- # Question Predict the output. ``` python x = 11 y = 2 z = 4 res = (x + y - z) ** (x % z) print(res) ``` # Choices - [x] 729 - [ ] 81 - [ ] 9 --- title: Quiz-4 explanation, `bool()` description: duration: 700 card_type: cue_card --- ### Quiz-4 explanation <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/418/original/quiz7.png?1689923709" width=500 height=350> ### The `bool()` function In Python, - Every number except 0 is `True`. - Every non-empty strings is `True`. Code: ``` python= bool(1) ``` >Output: ``` True ``` Code: ``` python= bool(0) ``` >Output: ``` False ``` Code: ``` python= bool(-123) ``` >Output: ``` True ``` Code: ``` python= bool("Hello") ``` >Output: ``` True ``` Code: ``` python= bool("") ``` >Output: ``` False ``` Code: ``` python= bool(" ") ``` >Output: ``` True ``` #### **Question:** Predict the output ```python print(bool('false')) ``` A. True B. False **Ans:** `True` #### **Question:** Predict the output ```python print(int(True)) ``` A. 1 B. 0 **Ans:** `1` --- title: Break & Doubt Resolution description: duration: 600 card_type: cue_card --- ### Break & Doubt Resolution `Instructor Note:` * Kindly take this time (up to 5-10 mins) to give a short break to the learners. * Meanwhile, you can ask the them to share their doubts (if any) regarding the topics covered so far. --- title: Comparison, Assignment & Logical operators description: duration: 2400 card_type: cue_card --- ## Comparison operators - operators such as `>`, `<`, `>=`, `<=`, `==`, `!=` <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/419/original/operators_comparison.png?1689924424" width=600 height=200> \ Code: ``` python= my_marks = 50 my_cousin_marks = 90 my_marks > my_cousin_marks ``` >Output: ``` False ``` Code: ``` python= my_marks == my_cousin_marks ``` >Output: ``` False ``` Code: ``` python= my_marks = 90 my_marks == my_cousin_marks ``` >Output: ``` True ``` Code: ``` python= my_marks!=my_cousin_marks ``` >Output: ``` False ``` ## Assignment operator - `=` is an assignment operator. - It assigns the RHS operand value to the LHS operand. Code: ``` python= a = 4 * 4 a ``` >Output: ``` 16 ``` Code: ``` python a = 5 a = a + 2 a ``` >Output: ``` 7 ``` <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/420/original/assignment_op.png?1689924874" width=500 height=250> \ Code: ``` python= # Question - What will be the output? marks = 50 correction = 0.5 marks = marks + correction marks = marks + correction marks ``` >Output: ``` 51.0 ``` Code: ``` python= # Question - What will be the output? a = 5 a += 2 print(a) a -= 2 print(a) a *= 2 print(a) ``` >Output: ``` 7 5 10 ``` ## Logical operators - `and`, `or`, `not` - used when there are multiple conditions <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/421/original/logical_op.png?1689925052" width=600 height=200> ### `and` operator - `True` only if all the conditions are satisfied. <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/422/original/and_op.png?1689925148" width=600 height=250> ### `or` operator - `True` if any one of the conditions is satisfied. <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/423/original/or_op.png?1689925216" width=600 height=350> ### Truth Tables - **x** and **y** are conditions - 1 is `True`, 0 is `False` #### Truth table for `and` <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/424/original/tt_for_and.png?1689925318" width=300 height=250> #### Truth table for `or` <img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/040/425/original/tt_or.png?1689925403" width=300 height=250> \ Code: ``` python= # Question - What will be the output? a=10 a>5 or a>20 or a<2 #True a>5 and a==20 and a<2 #False ``` >Output: > True False Code: ``` python= # Question - Check if a number is a multiple? amount = 1000 amount % 500 == 0 ``` >Output: ``` True ``` Code: ``` python= # ATM Dispatch amount= int(input("Please enter the amount to withdraw: ")) amount % 500 == 0 or amount % 200 == 0 ``` >Output: ``` Please enter the amount to withdraw: 2039 False ``` ### `not` operator - Works only with **boolean** operands. Code: ``` python= print(not True) print(not False) print(not 24 < 56) ``` Output: ``` False True False ``` --- title: Practice Coding Question(s) description: duration: 600 card_type: cue_card --- ### Practice Coding Question(s) You can pick the following question and solve it during the lecture itself. This will help the learners to get familiar with the problem solving process and motivate them to solve the assignments. <span style="background-color: pink;">Make sure to start the doubt session before you start solving the question.</span> Q. https://www.scaler.com/hire/test/problem/96782/

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully