GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 8 November 2020

 Class 12th sumita arora solutions || Chapter 1- Python Revision tour - 1 || Type-B

Q 1. Fill In the missing lines of code in the following code. The code reads in a limit amount a prices and prints the largest price that is less than the limit. You can assume that all prices and the limit are positive numbers. When a price 0 is entered the program terminates and prints the largest price that is less than the limit.

 

# Read the limit.

limit = float(input ('enter the limit'))

max_price = 0

#Read the next price

next_price = float(input ("Enter a price or to stop:"))

while next_price > 0 :

    <write your code here>

    # Read the next price

    <Write your code here>

if max_price > 0 :

    <Write your code here>

else :

    <Write your code here>

 

Answer =

 

# Read the limit.
limit = float(input ('enter the limit'))
max_price = 0
#Read the next price
next_price = float(input ("Enter a price or to stop:"))
while next_price > 0 :
    if next_price > max_price and next_price < limit :
        max_price = next_price
    # Read the next price
    next_price = float(input ("Enter a price or to stop:"))
if max_price > 0 :
    print("Largest number :-",max_price)
else :
    print("Invalid")


Q. Predict the outputs of the following programs: -

 

(a)

count = 0

while count < 10 :

    print ("Hello")

    count += 1

 

(b)

x = 10

y = 0

while x > y :

    print (x, y)

    x = x - 1

    y += 1

 

(c)

keepgoing = True

x = 100

while keepgoing :

    print (x)

    x = x - 10

    if x < 50 :

        keepgoing = False

 

(d)

x = 45

while x < 50 :

    print (x)

 

(e)

for x in [1,2,3,4,5] :

    print (x)

 

(f)

for p in range(1, 10) :

    print (p)

 

(g)

for z in range (-500, 500, 100) :

    print (z)

 

(h)

x = 10

y = 5

for i in range (x - y * 2) :

    print ("%", i)

   

(i)

c = 0

for x in range (10) :

    for y in range (5) :

        c += 1

print (c)

 

(j)

x = [1,2,3]

counter = 0

while counter < len(x) :

    print(x [counter] * '%' )

    for y in x :

        print(y *'* ')

    counter += 1

 

(k)

for x in 'lamp' :

    print(str.upper(x))

 

(l)

x = 'one'

y = 'two'

counter = 0

while counter < len(x) :

    print ( x[counter], y[counter])

    counter += 1

 

(m)

x = "apple, pear, peach"

y = x.split(", ")

for z in y :

    print(z)

 

(n)

x = 'apple, pear, peach, grapefruit'

y = x. split(', ' )

for z in y :

    if z < 'm' :

        print(str.lower(z))

    else :

        print(str.upper(z))

 

Answer =

(a)

Output:-

Hello

Hello

Hello

Hello

Hello

Hello

Hello

Hello

Hello

Hello

>>>

(b)

Output: -

10 0

9 1

8 2

7 3

6 4

>>>

(c)

Output: -

100

90

80

70

60

50

>>>

(d)

Output: -

45

45

45

45

45

45

45

45

45 infinite times.

(e)

Output: -

1

2

3

4

5

>>>

(f)

Output: -

1

2

3

4

5

6

7

8

9

>>> 

(g)

Output: -

-500

-400

-300

-200

-100

0

100

200

300

400

>>> 

(h)

It will give no output, because precedence of * operator is more than - operator.

So for value in range become zero after solving.

(i)

Output: -

 

50

>>> 

(j)

%

*

* *

* * *

%%

*

* *

* * *

%%%

*

* *

* * *

>>>

(k) 

L

A

M

P

>>> 

(l) 

o t

n w

e o

>>> 

(m) 

apple

pear

peach

>>> 

(n)

 apple

PEAR

PEACH

grapefruit

>>> 


Q. Find and write the output of the following python code:

 

for Name in ['Jayes', 'Ramya', 'Taruna', 'Suraj'] :

    print (Name)

    if Name[0] == 'T' :

        break

    else :

        print("Finished!")

print ('Got it!')

 

Answer =

Jayes

Finished!

Ramya

Finished!

Taruna

Got it!

>>> 


Q4. How many times will the following for loop execute and what's the output?

 

(i)

for i in range(-1, 7, -2) :

    for j in range (3) :

        print(1, j)

 

(ii)

for i in range (1, 3, 1) :

    for j in range (i+1) :

        print('*')

 

Answer =

(a)

There is no output because of invalid range command.

(b)

This program execute 5 times

Output -

*

*

*

*

*

>>> 


Q. Is the loop in the code below infinite? How do you know (for sure) before you run it?

 

m = 3

n = 5

while n < 10 :

    m = n - 1

    n = 2 * n - m

    print(n, m)

 

Answer =

This program execute finite because while loop have condition (n<10). So when n become greater than 10 then program break.




Credits to PATH WALA 



No comments:

Post a Comment