P.
Shreya                                    19321A0596
                          WEEK-3
1.Write a program to display hello world.
Syntax:
print(“Statement”)
Program:
print("Hello World!!")
Output:
Hello World!!
P.Shreya                                                19321A0596
2. Write a python program to implement data types.
Syntax:
type(variable_name)
Program:
num1=5
str1="hi this is python"
float1=3.79
complex1=7j
list1=["apple","banana","cherry"]
tuple1=("apple","banana","cherry")
bool1=True
set1={"apple", "banana", "cherry"}
dict1={"name" : "John", "age" : 36}
range1=range(4)
frozenset1 = frozenset({"apple", "banana", "cherry"})
print(num1, "is" ,type(num1))
print(str1, "is" ,type(str1))
print(float1, "is" ,type(float1))
print(complex1, "is" ,type(complex1))
print(list1, "is" ,type(list1))
print(tuple1, "is" ,type(tuple1))
print(bool1, "is" ,type(bool1))
print(range1, "is" ,type(range1))
print(dict1, "is" ,type(dict1))
print(set1, "is" ,type(set1))
print(frozenset1, "is" ,type(frozenset1))
P.Shreya                                                          19321A0596
Output:
5 is <class 'int'>
hi this is python is <class 'str'>
3.79 is <class 'float'>
7j is <class 'complex'>
['apple', 'banana', 'cherry'] is <class 'list'>
('apple', 'banana', 'cherry') is <class 'tuple'>
True is <class 'bool'>
range(0, 4) is <class 'range'>
{'name': 'John', 'age': 36} is <class 'dict'>
{'apple', 'cherry', 'banana'} is <class 'set'>
frozenset({'apple', 'cherry', 'banana'}) is <class 'frozenset'>
P.Shreya                                                 19321A0596
3. Write a python program to implement specific data types.
Syntax:
identifier=type(value)
Program:
str1 = str("Hello World")
num1= int(20)
float1= float(20.5)
complex1= complex(1j)
list1= list(("apple", "banana", "cherry"))
tuple1= tuple(("apple", "banana", "cherry"))
range1= range(6)
dict1= dict(name="John", age=36)
set1= set(("apple", "banana", "cherry"))
frozenset1= frozenset(("apple", "banana", "cherry"))
bool1= bool(5)
print(num1, "is" ,type(num1))
print(str1, "is" ,type(str1))
print(float1, "is" ,type(float1))
print(complex1, "is" ,type(complex1))
print(list1, "is" ,type(list1))
print(tuple1, "is" ,type(tuple1))
print(bool1, "is" ,type(bool1))
print(range1, "is" ,type(range1))
print(dict1, "is" ,type(dict1))
print(set1, "is" ,type(set1))
print(frozenset1, "is" ,type(frozenset1))
P.Shreya                                                          19321A0596
Output:
20 is <class 'int'>
Hello World is <class 'str'>
20.5 is <class 'float'>
1j is <class 'complex'>
['apple', 'banana', 'cherry'] is <class 'list'>
('apple', 'banana', 'cherry') is <class 'tuple'>
True is <class 'bool'>
range(0, 6) is <class 'range'>
{'name': 'John', 'age': 36} is <class 'dict'>
{'apple', 'cherry', 'banana'} is <class 'set'>
frozenset({'apple', 'cherry', 'banana'}) is <class 'frozenset'>
P.Shreya                                                          19321A0596
4.Write a python program to display usage of data types.(list,
tuple, set, frozenset, dict)
Syntax:
type(variable_name)
Program:
list1=["apple","banana","cherry"]
tuple1=("apple","banana","cherry")
set1={"apple", "banana", "cherry"}
dict1={"name" : "John", "age" : 36}
frozenset1 = frozenset({"apple", "banana", "cherry"})
Output:
['apple', 'banana', 'cherry'] is <class 'list'>
('apple', 'banana', 'cherry') is <class 'tuple'>
{'apple', 'cherry', 'banana'} is <class 'set'>
{'name': 'John', 'age': 36} is <class 'dict'>
frozenset({'apple', 'cherry', 'banana'}) is <class 'frozenset'>
P.Shreya                                                  19321A0596
5.Write a python program to illustrate arithmetic operators.
Syntax:
Result=operand arthoperator operand
Program:
x = 16
y=4
# Output: x + y = 20
print('the sum is x + y =',x+y)
# Output: x - y = 12
print('the difference is x - y =',x-y)
# Output: x * y = 64
print('the product is x * y =',x*y)
# Output: x / y = 4.0
print('the quotient is x / y =',x/y)
# Output: x // y = 4
print('the remainder is x // y =',x//y)
# Output: x ** y = 65536
print('the exponent of x ** y is =',x**y)
P.Shreya                            19321A0596
Output:
the sum is x + y = 20
the difference is x - y = 12
the product is x * y = 64
the quotient is x / y = 4.0
the remainder is x // y = 4
the exponent of x ** y is = 65536
P.Shreya                                                   19321A0596
6. Write a python program to illustrate relational operators.
Syntax:
Result=operand reloperator operand
Program:
a, b = 20, 50
print(a == b)
print(a != b)
print(a > b)
print(a < b)
print(a >= b)
print(a <= b)
Output:
False
True
False
True
False
True
P.Shreya                                            19321A0596
7.Write a python program to implement logical and assignment
operators.
Syntax:
Result=operand operator operand
Program:
x = 79
y=0
print('x and y is',x and y)
print('x or y is',x or y)
print('not x is',not x)
Output:
x and y is 0
x or y is 79
not x is False
P.Shreya                                                              19321A0596
Program:
a=7
Total = 31
Total += a # Using += Operator
print("The Value of the Total after using += Operator is: ", Total)
Total -= a # Using -= Operator
print("The Value of the Total after using -= Operator is: ", Total)
Total *= a # Using *= Operator
print("The Value of the Total after using *= Operator is: ", Total)
Total //= a # Using //= Operator
print("The Value of the Total after using //= Operator is: ", Total)
Total **= a # Using **= Operator
print("The Value of the Total after using **= Operator is: ", Total)
Total /= a # Using /= Operator
print("The Value of the Total after using /= Operator is: ", Total)
Total %= a # Using %= Operator
print("The Value of the Total after using %= Operator is: ", Total)
x = 11
y=6
x &= y # Using &= Operator
print("The Value of the x after using &= Operator is: ", x)
x |= 9 # Using |= Operator
print("The Value of the x after using |= Operator is: ", x)
x ^= y # Using ^= Operator
print("The Value of the x after using ^= Operator is: ", x)
P.Shreya                                                      19321A0596
Output:
The Value of the Total after using += Operator is: 38
The Value of the Total after using -= Operator is: 31
The Value of the Total after using *= Operator is: 217
The Value of the Total after using //= Operator is: 31
The Value of the Total after using **= Operator is: 27512614111
The Value of the Total after using /= Operator is: 3930373444.428571
The Value of the Total after using %= Operator is: 4.4285712242126465
The Value of the x after using &= Operator is: 2
The Value of the x after using |= Operator is: 11
The Value of the x after using ^= Operator is: 13
P.Shreya                                                19321A0596
8. Write a python program to check whether a number is positive.
Syntax:
if(condition):
  statement
Program:
num = float(input("Enter a number: "))
if num > 0:
  print("Positive number")
Output:
Enter a number: 9
Positive number
P.Shreya                                               19321A0596
9. Write a python program to check whether a number is positive
or negative.
Syntax:
if(condition):
  statement
else:
statement
Program:
num = float(input("Enter a number: "))
if num > 0:
  print("Positive number")
else:
  print("Negative number")
Output:
Enter a number: -7
Negative number
P.Shreya                                             19321A0596
10. Write a python program to check whether a number is zero,
positive or negative.
Syntax:
if(condition):
  statement
elif(condition):
  statement
else:
statement
Program:
num = float(input("Enter a number: "))
if num > 0:
  print("Positive number")
elif num == 0:
  print("Zero")
else:
  print("Negative number")
Output:
Enter a number: 0
Zero
P.Shreya                                                19321A0596
11.Write a python program to display numbers from 1 to 15.
Syntax:
for val in sequence:
     loop body
Program:
for i in range(1, 16):
     print(i)
print(“ “.join(str(i) for i in range(1,16)))
Output:
10
11
12
13
14
15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
P.Shreya                                                   19321A0596
12.Write a python program to illustrate the usage of for loop.
Syntax:
for val in sequence:
   loop body
Program:
numbers = [6, 51, 30, 8, 43, 26, 5, 4, 11]
sum = 0
for val in numbers:
   sum = sum+val
print("The sum is", sum)
Output:
The sum is 184
P.Shreya                                                  19321A0596
13.Write a python program to illustrate the usage of while loop.
Syntax:
while test_expression:
     Body of while
Program:
i=1
while i < 16:
    print(i)
    i += 2
Output:
11
13
15
P.Shreya                                            19321A0596
                                  WEEK-4
14.Write a python program implementing string quotes, string
indexing, string slicing and string methods
Syntax:
str=’string text’
str[index]
str[starting:ending:step]
str.method()
Program:
a = "this"
b = 'and that'
print(a, b)
print(b[5])
b1 = "Hello, World!"
print(b1[2:5])
text = 'In The WoRld of A Seed'
print("\nConverted String: uppercase ")
print(text.upper())
print("\nConverted String:lowercase")
print(text.lower())
print("\nConverted String: ")
print(text.title())
print("\nOriginal String")
print(text)
P.Shreya                      19321A0596
Output:
this and that
llo
Converted String: uppercase
IN THE WORLD OF A SEED
Converted String:lowercase
in the world of a seed
Converted String:
In The World Of A Seed
Original String
In The WoRld of A Seed
P.Shreya                                              19321A0596
15.Write a Python program to check whether a given number is a
prime number or not.
Program:
number = int(input("Enter any number: "))
if number > 1:
   for i in range(2, number):
        if (number % i) == 0:
           print(number, "is not a prime number")
           break
   else:
        print(number, "is a prime number")
else:
   print(number, "is not a prime number")
Output:
Enter any number: 8
8 is not a prime number
P.Shreya                                                          19321A0596
16.Write a Python program to print the Fibonacci series.
Program:
def Fibonacci(number):
           if(number == 0):
                   return 0
           elif(number == 1):
                   return 1
           else:
                   return (Fibonacci(number - 2)+ Fibonacci(number - 1))
number = int(input("Enter the Range Number: "))
for n in range(0, number):
           print(Fibonacci(n))
Output:
Enter the Range Number: 5
3
P.Shreya                                         19321A0596
17.Write a Python program to swap two numbers.
Program:
x = int(input("Enter a number1: "))
y = int(input("Enter a number2: "))
print ("Before swapping: ")
print("Value of x : ", x, " and y : ", y)
# code to swap 'x' and 'y'
x, y = y, x
print ("After swapping: ")
print("Value of x : ", x, " and y : ", y)
Output:
Enter a number1: 5
Enter a number2: 6
Before swapping:
Value of x : 5 and y : 6
After swapping:
Value of x : 6 and y : 5
P.Shreya                                             19321A0596
18.Write a Python program to check whether the entered string
and number is a palindrome or not.
Program:
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
   dig=n%10
   rev=rev*10+dig
   n=n//10
if(temp==rev):
   print("The number is a palindrome!")
else:
   print("The number isn't a palindrome!")
string = input("Please enter your own Text : ")
str1 = ""
for i in string:
   str1 = i + str1
print("Reverse Order : ", str1)
if(string == str1):
  print("This is a Palindrome String")
else:
  print("This is Not a Palindrome String")
Output:
Enter number:67976
The number is a palindrome!
Please enter your own Text : qwerty
Reverse Order :      ytrewq
P.Shreya                                            19321A0596
This is Not a Palindrome String
19.Write a python program to illustrate comments.
Program:
#print("Hello, World!")
print("Cheers, Mate!")
# Variable a holds value 5 (Multiline)
# Variable b holds value 10
# Variable c holds sum of a and b
# Print the result
a=5
b = 10
c = a+b
print("The sum is:", c)
Output:
Cheers, Mate!
The sum is:15
P.Shreya                                              19321A0596
20.Write a python program to check whether the given number is
an Armstrong number or not.
Program:
num = int(input("Enter a number: "))
sum = 0
temp = num
while temp > 0:
  digit = temp % 10
  sum += digit ** 3
  temp //= 10
if num == sum:
  print(num,"is an Armstrong number")
else:
  print(num,"is not an Armstrong number")
Output:
Enter a number: 153
153 is an Armstrong number