0% found this document useful (0 votes)
19 views2 pages

LecNotes 20012025

The document discusses relational and logical operators in Python, including their precedence and how strings are compared based on ASCII codes. It also provides examples for evaluating expressions and an exercise to calculate the perimeter and area of a triangle using user-inputted side lengths. Additionally, it includes specific expressions for evaluation with given variable values.

Uploaded by

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

LecNotes 20012025

The document discusses relational and logical operators in Python, including their precedence and how strings are compared based on ASCII codes. It also provides examples for evaluating expressions and an exercise to calculate the perimeter and area of a triangle using user-inputted side lengths. Additionally, it includes specific expressions for evaluation with given variable values.

Uploaded by

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

‭Programming with Python (2)‬

‭Note: Brief Summary of contents discussed.‬

‭Relational Operators:‬

‭Used for comparing two expressions and yield True or False‬

‭==, <, >, <=, >=‬

‭-‬ S
‭ trings are compared left to right, characters by characters, based on ASCII‬
‭codes.‬

‭ SCII code range:‬


A
‭‘A’ - ‘Z’ [65-90]‬
‭‘a’ - ‘z’ [97-122]‬
‭‘0’ - ‘9’ [48-57]‬

‭[0-9] < [A-Z] < [a-z]‬

‭-‬ ‭If a string is a prefix of another string, the longer string is considered longer.‬

‭Logical Operators‬

(‭ in order of precedence/priority)‬
‭not,‬
‭and,‬
‭or‬

‭Order of precedence‬

‭Arithmetic operators > Relational Operators > Logical Operators‬

‭Arithmetic operators: +, -, *, /, //, **, %‬

‭Commenting a line of code in Python: Use ‘#’‬


‭Apply parenthesis the following expressions and evaluate‬

a‭ .‬ ‭not 9 == 8 and 7+1!=8 or 6 < 4.5‬


‭b.‬ ‭7 ** 2 // 9 % 3‬
‭c.‬ ‭5 % 10 + 10 - 25 * 8 // 5‬
‭d.‬ ‭10!=9 and 29 >= 29 and ‘hi’ > ‘hello’ or ‘bye’ < ‘Bye’ and 7 <= 2.5‬
‭e.‬ ‭7 ** 2 // 4+5 > 8 or 5!=6‬

‭Exercise: Perimeter and Area of a triangle with given sides‬

‭Write a program that:‬


‭-‬ ‭Ask the user for three sides of triangle‬
‭-‬ ‭Calculate the Perimeter and Area‬

#‭ use ** operator for computing square root.‬


‭Note: s = (a + b + c)/2 , Area = sqrt(s(s-a)(s-b)(s-c))‬

‭Apply parenthesis and evaluate‬

1‭ .‬
‭x < y or not z == y‬

(‭ a)‬‭When x=0, y=6, z=10‬


‭(b)‬ ‭When x=1, y=1, z=1‬

‭2.‬

‭10 < 5 and 5/0 < 10‬

3‭ .‬
‭10 > 5 and 5/0 < 10‬

You might also like