# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Assignment No 2

# +
Q1. What are the two values of the Boolean data type? How do you write them?

Solution:- A variable of the primitive data type boolean can have two values true and false 
           Ex:- A = True 
                B = False
           Ex2:- a = 5
                 b = 10
                 a<b

# +
Q2. What are the three different types of Boolean operators?

Solution:- There are three types of boolean operators.
        1.AND operator (&& or “and”)
        2.OR operator (|| or “or”)
        3.NOT operator (not)

# +
Q3 Make a list of each Boolean operator truth tables (i.e. every possible combination of Boolean
values for the operator and what it evaluate.

Solution:- 
1. (AND)The and operator takes two arguments. It evaluates to False unless both inputs are True. 
 A         B     A and B
True    True      True
False   True      False
True    False     False
False   False     False 
                                                      
2. (OR) The value of the or operator is True unless both of its inputs are False. 

A        B       A or B
True    True     True
False   True     True
True    False    True
False   False    False

# +
Q4 What are the values of the following expressions?

1. (5 > 4) and (3 == 5) :- False
2. not (5 > 4) :- False
3. (5 > 4) or (3 == 5) :- True
4. not ((5 > 4) or (3 == 5)) :- False
5. (True and True) and (True == False) :- False
6. (not False) or (not True) :- True

# +
Q5. What are the six comparison operators?

Solution :- 
1. Less than(<)
2. Greater than(>)
3. Less than or equal to(<=) 
4. Greater than or equal to(>=)
5. Equal to(==)
6. Not equal to (!=).

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

Solution:- The “=” is an assignment operator is used to assign the value on the right to the variable on the left. 
           The '==' operator checks whether the two given operands are equal or not. If so, it returns true. Otherwise it returns false.
Ex :- A = 10 #Assign the value by using Assignment Operator
      B = 10
      A == B #Checking the conditon by using equal to operator.

# +
Q7. Identify the three blocks in this code:
    spam = 0
    if spam == 10:
    print('eggs')
    if spam > 5:
    print('bacon')
    else:
    print('ham')
    print('spam')
    print('spam')

Solution :- 1st Declear a Variable spam and Assigned value as 0.
            2nd check the condition is spam == 10 if yes then print eggs if no then otherwise terminate the loop.
            3rd check the condition if spam > 5 if yes  then print bacon if no then goto else part and print next all statement.
            
output is the above code :- ham
                            spam
                            spam

# +
Q8. 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.

Solution :- 
            spam = int(input("Enter the Number :- "))
            if spam == 1:
                print('Hello')
            elif spam == 2 :
                print('Howdy')
            else:
                print('Greetings!')

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

Solution :- if it will Happend at the time of excution then i will press Ctrl + C.
            if when i will write a program then i used break keyword for controling loop.. otherwise my code are stuck.

# +
Q10. How can you tell the difference between break and continue?

Solution :- 

    1. Break :- When a break statement is encountered then the control is exited from the loop construct immediately.
               syntax :- break
                
    2. Continue :- When the continue statement is encountered then the control automatically passed from the beginning of the loop statement.
                   Syntax :- continue

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

Solution :- No such diffrence it will be work same but if we change the 1st 2nd 3rd value then it will be work different.

# +
Q12. 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.

Solution :- 

1. for i in range(0,10):
     print(i)
        
2. i = 0 
   while i <= 10:
        print(i)
        i = i + 1
# -

for i in range(0,10):
    print(i)

i = 0 
while i <= 10:
    print(i)
    i = i + 1

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

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

StarcoderdataJupyterScriptsDedupFiltered