top of page

Python Tutorial and Programming Practice Set- 2

realcode4you

Question 1:

What are the two values of the Boolean data type? How do you write them?

Ans:

Two values of Boolean data type: 0 and 1

It is written as False and true respectively.


Question 2:

What are the three different types of Boolean operators?

Ans:

Three different types of Boolean operators: AND ,OR ,NOT


Question 3:

Make a list of each Boolean operator's truth tables (i.e. every possible combination of Boolean values for the operator and what it evaluate ).

Ans:

















Question 4:

What are the values of the following expressions?

Ans:

(5 > 4) and (3 == 5):Ans:False(0)

not (5 > 4):Ans: False(0)

(5 > 4) or (3 == 5):Ans: True(1)

not ((5 > 4) or (3 == 5)):Ans: False(0)

(True and True) and (True == False):Ans:False(0)

(not False) or (not True):Ans:True(0)


Question 5:

What are the six comparison operators?

Ans:

==,!=,>,<,>=,<=


Question 6:

How do you tell the difference between the equal to and assignment operators?Describe a condition and when you would use one.

Ans:

Equal to:==(compares whether both values are same or not)

Assignment operators: assign values to variables(x=2,y=3 where x assumes value 2 and y as 3 untill modified.


Question 7:

Identify the three blocks in this code:

spam = 0 Ans: Value Assignment

spam = 0 Ans: Value Assignment

print('eggs')

if spam > 5: Ans: If condition

print('bacon')

else: Ans: else block

print('ham')

print('spam')

print('spam')


Question 8:

Write code that prints Hello if 1 is stored in spam, prints Howdy if 2 is stored in spam, and prints Greetings! if anything else is stored in spam.

Ans: Spam=input(enter spam value)

If spam==1:

print(“hello”)

elif spam==2:

print(“howdy”)

else

print(“greetings”)


Question 9:

If your programme is stuck in an endless loop, what keys you’ll press?

Ans: Ctrl+C keys


Question 10:

How can you tell the difference between break and continue?

Ans:

Break statement makes the control come out of loop

Continue statement takes the control for next iteration


Question 11:

In a for loop, what is the difference between range(10), range(0, 10), and range(0, 10, 1)?

Ans:

No difference .Range will take value for 0 to 9


Question 12:

Write a short program that prints the numbers 1 to 10 using a for loop. Then write an equivalent program that prints the numbers 1 to 10 using a while loop.

Ans: for I in range(1,11):

print(i)


I=1

While i<11:

print(i)

i=I+1



Question 13:

If you had a function named bacon() inside a module named spam, how would you call it after importing spam?

Ans: This function can be called with spam. bacon()




If you have any query or need any help in python programming, python assignment or python homework then send your requirement details at:



and get instant help with an affordable price.


Leave your comment in below comment section to suggest your answers which is related to these questions so we can modify to make it better.


Comments


REALCODE4YOU

Realcode4you is the one of the best website where you can get all computer science and mathematics related help, we are offering python project help, java project help, Machine learning project help, and other programming language help i.e., C, C++, Data Structure, PHP, ReactJs, NodeJs, React Native and also providing all databases related help.

Hire Us to get Instant help from realcode4you expert with an affordable price.

USEFUL LINKS

Discount

ADDRESS

Noida, Sector 63, India 201301

Follows Us!

  • Facebook
  • Twitter
  • Instagram
  • LinkedIn

OUR CLIENTS BELONGS TO

  • india
  • australia
  • canada
  • hong-kong
  • ireland
  • jordan
  • malaysia
  • new-zealand
  • oman
  • qatar
  • saudi-arabia
  • singapore
  • south-africa
  • uae
  • uk
  • usa

© 2023 IT Services provided by Realcode4you.com

bottom of page