<jupyter_start><jupyter_text>Assignment 2   1.What are the two values of the boolean data types? how do you write them ?**Ans**: Boolean values has two types: 'True' and 'False'. we write them as below<jupyter_code>true_val=True
false_val=False
print(true_val,type(true_val))
print(false_val,type(false_val))<jupyter_output>True <class 'bool'>
False <class 'bool'><jupyter_text>2. What are the three different types of Boolean operators?**Ans**: `are` `and` `not` are the three differnt types of Boolean operators in python are. we write them as below<jupyter_code>num1=500
num2=800
print(num1>300 and num2>900) # Example of boolean and
print(num1>200 or num2>700) # Example of boolean or
print(not(num1>100)) # Example of boolean not<jupyter_output>False
True
False<jupyter_text>3. Make a list of each Boolean operator&39;s truth tables (i.e. every possible combination of Boolean values for the operator and what it evaluate) ?**Ans:** The Truth tables for the boolean tables are as follows:  | |   | AND TABLE   |  A and B|---:|:-------------|:-----------|:------|| 1 | True  | False       | False   || 2 | True  | True    | True  | | 3 | False  | True    | False  | | 4 | False  | False    | False   | | |   | OR TABLE   |     A or B|---:|:-------------|:-----------|:------|| 1 | True  | False       | False   || 2 | True  | True    | False  | | 3 | False  | True    | False  | | 4 | False  | False    | True   | | |  NOT TABLE |  not A|---:|:-------------|:-----|| 1 | True  | False || 2| False  | True  |     4. What are the values of the following expressions ?* (5 &gt; 4) and (3 == 5)  * not (5 &gt; 4)  * (5 &gt; 4) or (3 == 5)  * not ((5 &gt; 4) or (3 == 5))  * (True and True) and (True == False)  * (not False) or (not True)<jupyter_code>print((5>4)and(3==5)) # False
print(not(5>4)) # False
print((5>4)or(3==5)) # True
print(not((5>4)or(3==5))) # False
print((True and True)and(True==False)) # False
print((not False)or(not True)) # True<jupyter_output>False
False
True
False
False
True<jupyter_text>5. What are the six comparison operators?**Ans:**  The Six comparision operators available in python are:  `==` , `!=` , `` , ``  6. How do you tell the difference between the equal to and assignment operators?Describe a condition and when you would use one ? **Ans:** `==` is the equal to operator that compares two values and evaluates to a Boolean, while `=` is that assignment operator that stores a value in a variable.<jupyter_code>a=3 # Assigning operator that stores 3 value in a variable a
if a==3:#comparing values of a varible value and 3
    print(a==3)<jupyter_output>True<jupyter_text>7. 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')**Ans**: In Python, code block refers to a collection of code that is in the same block or indent. This is most commonly found in classes, functions, and loops.<jupyter_code>spam = 0  
if spam == 10:  
    print('eggs')  # block #1
if spam > 5:  
    print('bacon')  # block #2
else:  
    print('ham')  # block #3
print('spam')  
print('spam')<jupyter_output>ham
spam
spam<jupyter_text>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.<jupyter_code>def spamCode(spam):
    if spam==1:
        print('Hello')
    elif spam==2:
        print('Howdy')
    else:
        print('Greetings')
        
spamCode(1) 
spamCode(2)
spamCode(3)<jupyter_output>Hello
Howdy
Greetings<jupyter_text>9.If your programme is stuck in an endless loop, what keys you’ll press?**Ans:** Press `Ctrl-c` to stop a program stuck in an infinite loop  10. How can you tell the difference between break and continue?**Ans:** The `break` statement will move the execution outside the loop if break condtion is satisfied. Whereas the `continue` statement will move the execution to the start of the loop.  11. In a for loop, what is the difference between range(10), range(0, 10), and range(0, 10, 1)?**Ans:** The Differences are as follows:  1. The _**range(10)**_ call range from 0 to 9 (but not include 10)  2. The _**range (0,10)**_ explicitly tells the loop to start at 0  3. The _**range(0,10,1)**_ explicitly tells the loop to increase the variable by 1 on each iteration     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 ?<jupyter_code>print('-'*10,'Using For Loop','-'*10)
for i in range(1,11):
    print(i, end=" ")
print('\n')
print('-'*10,'Using While Loop','-'*10) 
i=1
while i<=10:
    print(i, end=" ")
    i+=1<jupyter_output>---------- Using For Loop ----------
1 2 3 4 5 6 7 8 9 10 

---------- Using While Loop ----------
1 2 3 4 5 6 7 8 9 10
StarcoderdataJupyterStructuredCleanDedup