[go: up one dir, main page]

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

Assignment 2

The document discusses Python control flow structures like if statements. It provides the syntax for if statements and examples. It also covers Boolean expressions and conditional statements.
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)
45 views2 pages

Assignment 2

The document discusses Python control flow structures like if statements. It provides the syntax for if statements and examples. It also covers Boolean expressions and conditional statements.
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

PRTHON 3.

0
Control Flow Structure
• The reserved word if begins a if statement.
• The condition is a Boolean expression that determines whether or not the body will be executed. A colon (:) must follow the
condition.
• The block is a block of one or more statements to be executed if the condition is true. Recall that the statements within a
block must all be indented the same number of spaces from the left. The block within an if must be indented more spaces than
the line that begins the if statement. The block technically is part of the if statement. This part of the if statement is sometimes
called the body of the if.
Syntax: print('ten') Ex:d1 = 1.11 - 1.10
if condition: if 1: d2 = 2.11 - 2.10
block print('one') print('d1 =', d1, ' d2 =', d2)
Ex. always prints one, while the if d1 == d2:
if x < 10: statement print('Same')
y=x if 0: else:
could be written print('zero') print('Different')
if x < 10: y = x Syntax: IF with OR and AND
but may not be written as if condition : x <= y and x <= z
if x < 10: if block x < y or x > y
y=x else: if x == 1 or 2 or 3:
if x == 10: else block print("OK")
Condition (If, Switch and Nested) [Dis=Sales*<Dis_percentage >)/100] ,[Total
WAP to find no is –ve or +ve Amount=Sales-Dis]
WAP to find no is even and odd 1. WAP to print the Income, Tax & Surcharge of Employ.
WAP to find elder person in 2 persons The Tax and Surcharge based on the following conditions
WAP to find given year is leap year or not Income Tax %
WAP to display age is greater than 18 or not Surcharge
WAP to find Person is senior citizen or not, input age < Rs. 15000 15% 7%
WAP to find which no is greater no in 2 numbers Rs. 15001 to Rs. 20000 18% 11%
WAP to find which no is lowest no in 2 numbers Above Rs. 21000 20% 13%
WAP to find which no is greater no in 3 numbers [Total Income =Income- Tax-Surcharge][Tax=Income<
WAP to find which no is greater no in 4 numbers Tax_percentage >)/100]display all information like
WAP to find which no is lowest no in 3 numbers Income, Tax & Surcharge .
WAP to find which no is lowest no in 4 numbers 2. WAP to print the Division :
WAP to check whether a number is divisible by 5 and 11 or Per Division
not. < 40 Failed
WAP to display Digit in text (0 to 9) 40 to 50 Third
WAP to Check given character is vowel or not. 50 to 60 Second
Write a menu driven program to calculate: >=60 First
Area of circle[A=πr ]2 3. WAP to get input distance and print fare for the passenger
Area of squire [A=a*a] according to:
Area of rectangle[A=l*b] DISTANCE FARE (in Rs.)
WAP to Assign a stream to student according: Upto 20km 10 P/K
Marks obtained in diff. subject Stream Next 20km 7 P/K
Eng., Maths and Science >=80% Pure Science Above 6 P/K
Eng., and Science >=80%, Maths 4. WAP to for library charges a fine for books returned
Bio. Science late. Following are the fines :
>=60%
Eng., Maths and Science >=60% Commerce First five days : 40 paisa per day.
Six to ten day : 65 paisa per day.
WAP to print the Discount in Rupees for a salesman. The
Above ten days : 80 paisa per day
Discount is based on the following conditions
Sales Dis % 5. WAP to for Electric Bill charges according to charges.
< Rs. 5000 5% Following are the fines :
First 100 Units : 1 Rs per day.
Rs. 5000 to Rs. 10000 8%
Next200 Units : 2 Rs per day.
Above Rs. 10000 10%
Page 1 of 2
PRTHON 3.0
Above300 Units : 4 Rs per day. 1. not (x == 2)
Q1. Given the following definitions: b1, b2, b3, b4 = 2. x < 2 or x == 2
true, false, x == 3, y < 3 evaluate the following Boolean 3. not (x < y)
expressions:
4. not (x <= y)
1. b3 1) True
2. b4 2) False 5. x < 10 and x > 20
3. not b1 3) False 6. x > 10 or x < 20
4. not b2 4) True 7. x != 0
5. not b3 5) False 8. x == 0
6. not b4 6) True Q5. Consider the following Python code fragment:
7. b1 and b2 7) 0
8. b1 or b2 8) 1
9. b1 and b3 9) True
10. b1 or b3 10) 1
11. b1 and b4 11) False
12. b1 or b4 12) 1
13. b2 and b3 13) 0
14. b2 or b3 14) True
15. b1 and b2 or b3 15) True
16. b1 or b2 and b3 16) 1
17. b1 and b2 and b3 17) 0
18. b1 or b2 or b3 18) 1 What will the code print if the variables i, j, and k have the
19. not b1 and b2 and b3 19) False following values?
20. not b1 or b2 or b3 20) True (a) i is 3, j is 5, and k is 7
21. not (b1 and b2 and b3) 21) True (b) i is 3, j is 7, and k is 5
22. not (b1 or b2 or b3) 22) False (c) i is 5, j is 3, and k is 7
23. not b1 and not b2 and not b3 23) False (d) i is 5, j is 7, and k is 3
24. not b1 or not b2 or not b3 24) True (e) i is 7, j is 3, and k is 5
25. not (not b1 and not b2 and not b3) 25) True (f) i is 7, j is 5, and k is 3
26. not (not b1 or not b2 or not b3) 26) False Q7. Consider the following Python program that prints
one line of text:
Q2. The following section of code assigns the indicated
values to a bool:
x = 10 y = 20
b = (x == 10) # assigns True to b
b = (x != 10) # assigns False to b
b = (x == 10 and y == 20) # assigns True to b
b = (x != 10 and y == 20) # assigns False to b
b = (x == 10 and y != 20) # assigns False to b
b = (x != 10 and y != 20) # assigns False to b
b = (x == 10 or y == 20) # assigns True to b
b = (x != 10 or y == 20) # assigns True to b
b = (x == 10 or y != 20) # assigns True to b
b = (x != 10 or y != 20) # assigns False to b
Q3. Given the following definitions: x, y, z = 3, 5, 7
evaluate the following Boolean expressions:
1. x == 3 What will the program print if the user provides the following
2. x<y input?
3. x >= y (a) 3 (b) 21 (c) 5 (d) 17 (e) -5
4. x <= y
5. x != y - 2
6. x < 10
7. x >= 0 and x < 10
8. x < 0 and x < 10
9. x >= 0 and x < 2
10. x < 0 or x < 10
11. x > 0 or x < 10
x < 0 or x > 10
Q4. Express the following Boolean expressions in
simpler form; that is, use fewer operators. x is an
integer.
Page 2 of 2

You might also like