# ---
# 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
# ---

# # <NAME> 
# ## Reg 180905188
# ### Roll No 29 C

#
# ## 1. Write a program to find the area of rectangle. Take input from user.
# ## Eg.  x= int(input(‘Enter number:’))

# +
length = int(input("Enter number:"))
breadth = int(input("Enter number:"))


print("length is :" , length )
print("breadth  is :" ,  breadth)
print("Area of rectangle is :" , length * breadth)


# -

# ## 2. Write a program to swap the values of two variables.

# +
def swap():
    a = 5
    b = 7 
    print("a = " , a ,  "b= " , b)

    temp = a
    a = b 
    b = temp

    print("a = " , a ,  "b= " , b)

swap()

# -

# ## 3. Write a program to find whether a number is even or odd.

# +
def odd_or_even(num):
    return (num % 2) == 0

print(odd_or_even(7))


# -

# ## 4. Write a program to check the largest among the given three numbers.

# +
def largest_among_three(a,b,c):

    if a > b and a > c:
        return a
    elif b > a and b > c:
        return b
    else:
        return c


a = 5
b = 6
c = 7
print(largest_among_three(a,b,c)) 

# -

# ## 5. Write a program to demonstrate while loop with else.

for i in range(1,5):
    print("Loop iteration : " , i)
else:
    print("inside else")

# ## 6. Write a program to print the prime numbers for a user provided range.

# +

lower = int(input())
upper = int(input())

print("Prime numbers between", lower, "and", upper, "are:")

for num in range(lower, upper + 1):
   # all prime numbers are greater than 1
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
           print(num)
# -

# ## 7. Write a program to demonstrate List functions and operations.

# +
my_list = [1,2,3,4]
print(my_list)

my_list.append(5)
print(my_list)

my_list.pop()
print(my_list)

my_list.insert(2,100)
print(my_list)

my_list2 = my_list.copy()
print(my_list2)


my_list.reverse()
print(my_list)

my_list.sort()
print(my_list)

my_list.count(2)
print(my_list)

print("index of 2 in the list is :", my_list.index(2))

my_list.clear()
print(my_list)


# -

# ## 8. Consider the tuple(1,3,5,7,9,2,4,6,8,10). Write a program to print half its values in one line and the other half in the next line.

# +
my_tuple = (1,3,5,7,9,2,4,6,8,10)
list1 = []
list2 = []

for i in my_tuple:
    if i % 2 == 0:
        list1.append(i)
    else:
        list2.append(i)
        

print(list1)
print(list2)
# -

# ## 9. Consider the tuple (12, 7, 38, 56, 78 ). Write a program to print another tuple whose values are even number in the given tuple.

# +
input = (12, 7, 38, 56, 78 )

even_list = []

for i in input:
    if i % 2 == 0:
        even_list.append(i)
        
even_tuple = tuple(even_list)
print(even_tuple)
# -

# ## 10. Write a Python program to print negative Numbers in a List  using for loop. Eg. [11, -21, 0, 45, 66, -93]. 

# +
input_list = [11, -21, 0, 45, 66, -93]

for i in input_list:
    if i < 0:
        print(i)
# -

# ## 11. Write a program to print negative Numbers in a List using while loop.  

# +
input_list = [11, -21, 0, 45, 66, -93]
i = 0

while i < 6:
    if input_list[i] < 0:
        print(input_list[i])
    i = i + 1
# -

# ## 12. Write a Python program to count positive and negative numbers in a List.

# +
input_list = [11, -21, 0, 45, 66, -93]

positives = 0
negatives = 0

for i in input_list:
    if i < 0:
        negatives = negatives + 1
    elif i > 0:
        positives = positives + 1

print("positives: " , positives)
print("negatives: " , negatives)
# -

# ## 13. Write a Python program to remove all even elements from a list  .

# +
num_list = [11, 21, 10, 45, 66, 93]

print(num_list)

for i in num_list:
    if i % 2 == 0:
        num_list.remove(i)

print(num_list)
# -

# ## 14. Define a dictionary containing Students data {Name, Height, Qualification}.
#     a) Convert the dictionary into DataFrame 
#     b) Declare a list that is to be converted into a new column (Address}
#     c) Using 'Address' as the column name  and equate it to the list and display the result.

# +
my_dict = { "Name" : [ "Kaustav" , "Sahil" ],
"Height" :  [ "170 cm" , "165 cm" ] ,
"Qualification" : ["B. Tech CSE" , "B. Tech CSE"] }

print(my_dict)
print()

import pandas as pd

df_my_dict = pd.DataFrame.from_dict(my_dict)
print(df_my_dict)
print()



address_list = ["Gurgaon" , "Jammu"]
df_my_dict["Address"] = address_list
print(df_my_dict)

# -

# ##     15.   Define a dictionary containing Students data {Name, Height, Qualification}.
#     a) Convert the dictionary into DataFrame 
#     b) Use DataFrame.insert() to add a column and display the result.

# +
my_dict = { "Name" : [ "Kaustav" , "Sahil" ],
"Height" :  [ "170 cm" , "165 cm" ] ,
"Qualification" : ["B. Tech CSE" , "B. Tech CSE"] }

print(my_dict)
print()

import pandas as pd

df_my_dict = pd.DataFrame.from_dict(my_dict)
print(df_my_dict)
print()


address_list = ["Gurgaon" , "Jammu"]
df_my_dict.insert(column="Address" , value=address_list , loc=3 )
print(df_my_dict)

# -

# ## End



StarcoderdataJupyterScriptsDedupFiltered