Showing posts with label Class XI Python Test. Show all posts
Showing posts with label Class XI Python Test. Show all posts

Python : Looping Statement Test 4

Python : Looping Statement Test 4

Q1. What is the use of range function in python?

Q2. Name three jump statements in python and explain any one.

Q3. Write the output of the following program.

Code

Output

x = "123"

for i in x:

  print(i)

 

 

i=8

while True:

  if i%3==0:

    break

  print("A")

 

 

i=9

while True:

  if i%3==0:

    break

  print("A")

 

 

i=0

while i<3:

  print(i)

  i=i+1

else:

  print(0)

 

 

i=0

while i<3:

  print(i)

  i=i+1

print(0)

 

 

i=0

while i<3:

  print(i)

  i=i+1

  print(0)

 

 

i=2

for x in range(i):

  i+=1

  print(i)

  print(i)

 

 

i=2

for x in range(i):

  x+=1

  print(x)

print(x)

 

 

i=2

for x in range(i):

  x+=1

  print(x)

  print(x)

 

 

i=100

while i<57:

  print(i)

  i+=5

 

 

i=100

while i>57:

  print(i+1)

  i+=5

 

 

 

Q4. Write the output and convert it into for loop.

i=100

while i>57:

               print(i)

               i-=5

 

 

Solution of Q3.

Code

Output

x = "123"

for i in x:

  print(i)

 

1

2

3

i=8

while True:

  if i%3==0:

    break

  print("A")

 

Infinite loop

i=9

while True:

  if i%3==0:

    break

  print("A")

 

No Output

i=0

while i<3:

  print(i)

  i=i+1

else:

  print(0)

 

0

1

2

0

i=0

while i<3:

  print(i)

  i=i+1

print(0)

 

0

1

2

0

i=0

while i<3:

  print(i)

  i=i+1

  print(0)

 

0

0

1

0

2

0

i=2

for x in range(i):

  i+=1

  print(i)

  print(i)

 

3

3

4

4

i=2

for x in range(i):

  x+=1

  print(x)

print(x)

 

1

2

2

i=2

for x in range(i):

  x+=1

  print(x)

  print(x)

 

1

1

2

2

i=100

while i<57:

  print(i)

  i+=5

 

No Output

i=100

while i>57:

  print(i+1)

  i+=5

 

Infinite loop

 


Python : Conditional Statement Test 7

 

 

Python : Conditional Statement Test 7


Q1. Evaluate the following statements:

 

a=True

b=True

c=True

d=True

 

1.          print(c)
2.          print(d)
3.          print(not a)
4.          print(not b )
5.          print(not c )
6.          print(not d)
7.          print(a and b )
8.          print(a or b )
9.          print(a and c)
10.       print(a or c )
11.       print(a and d )
12.       print(a or d)
13.       print(b and c )
14.       print(b or c )
15.       print(a and b or c)
16.       print(a or b and c )
17.       print(a and b and c)
18.       print(a or b or c )
19.       print(not a and b and c)
20.       print(not a or b or c )
21.       print(not (a and b and c))
22.       print(not (a or b or c) )
23.       print(not a and not b and not c)
24.       print(not a or not b or not c )
25.       print(not (not a or not b or not c))

SOLUTIONS
 
  1.  True
  2. True
  3. False
  4. False
  5. False
  6. False
  7. True
  8. True
  9. True
  10. True
  11. True
  12. True
  13. True
  14. True
  15. True
  16. True
  17. True
  18. True
  19. False
  20. True
  21. False
  22. False
  23. False
  24. False
  25. True

Python : Conditional Statement Test 5

 

Python : Conditional Statement Test 5

Q1. Accept the following from the user and 

    calculate the percentage of class attended:

a.     Total number of working days

b.     Total number of absent

    If the percentage is less than 75, than            student will not be able to sit in exam.

Q2. Accept the marks from the user and display the

    grade according to the following criteria:

    a. Below 25 - D

    b. 25 to 45 - C

    c. 45 to 50 - B

    d. 50 to 60 – B+

    e. 60 to 80 - A

    f. Above 80 – A+

Q3. A company decided to give bonus to employee 

    according to following criteria:

    Year of Service               Bonus

    More than 10 years            10%

    >=6 and <=10                  8%

    Less than 6 years             5%

    Ask user for their salary and year of service     and print the net bonus amount.

Q4. Accept the marked price from the user and 

    calculate the Net amount as(Marked Price –

    Discount) to pay according to following 

    criteria:

Marked Price

Discount

>10000

20%

>7000 and <=1000

15%

<=7000

10%

 

Q5. Write a program to accept percentage and

    display the Category according to the

    following category :

Per

Category

< 40

Failed

>=40 & <55

Fair

>=55 & <65

Good

>=65

Excellent

 

Q6. Accept three sides of a triangle and check 

    whether it is an equilateral, isosceles or 

    scalene triangle.

Note :

An equilateral triangle is a triangle in which all three sides are equal.

A scalene triangle is a triangle that has three unequal sides.

An isosceles triangle is a triangle with (at least) two equal sides.

Q7. Write a program to accept two numbers and 

    mathematical operators and perform operation 

    accordingly.

Like:

Enter First Number: 7

Enter Second Number : 9

Enter operator : +

Your Answer is : 16

Q8. Accept the age, sex (‘M’, ‘F’), number of days

    and display the wages accordingly

Age

Sex

Wage/day

>=18 and <30

M

700

F

750

>=30 and <=40

M

800

F

850

If age does not fall in any range then display the following message:

“Enter appropriate age”

 

Most Recently Published

File Handling Test 6

 File Handling Test 6 Q1 . Do we need to use the close() function when we use 'with' statement to open a file? Q2. Which mode you wi...

CS - IP Assignment/Worksheet