Recordprgms
Recordprgms
Shreya 19321A0596
WEEK-3
Syntax:
print(“Statement”)
Program:
print("Hello World!!")
Output:
Hello World!!
P.Shreya 19321A0596
Syntax:
type(variable_name)
Program:
num1=5
float1=3.79
complex1=7j
list1=["apple","banana","cherry"]
tuple1=("apple","banana","cherry")
bool1=True
range1=range(4)
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
Syntax:
identifier=type(value)
Program:
num1= int(20)
float1= float(20.5)
complex1= complex(1j)
range1= range(6)
bool1= bool(5)
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
Syntax:
type(variable_name)
Program:
list1=["apple","banana","cherry"]
tuple1=("apple","banana","cherry")
Output:
Syntax:
Program:
x = 16
y=4
# Output: x + y = 20
# Output: x - y = 12
# Output: x * y = 64
# Output: x / y = 4.0
# Output: x // y = 4
# Output: x ** y = 65536
Output:
the sum is x + y = 20
the difference is x - y = 12
the product is x * y = 64
the remainder is x // y = 4
Syntax:
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
Syntax:
Program:
x = 79
y=0
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
print("The Value of the Total after using += Operator is: ", Total)
print("The Value of the Total after using -= Operator is: ", Total)
print("The Value of the Total after using *= Operator is: ", Total)
print("The Value of the Total after using //= Operator is: ", Total)
print("The Value of the Total after using **= Operator is: ", Total)
print("The Value of the Total after using /= Operator is: ", Total)
print("The Value of the Total after using %= Operator is: ", Total)
x = 11
y=6
x |= 9 # Using |= Operator
x ^= y # Using ^= Operator
Output:
The Value of the Total after using **= Operator is: 27512614111
Syntax:
if(condition):
statement
Program:
if num > 0:
print("Positive number")
Output:
Enter a number: 9
Positive number
P.Shreya 19321A0596
Syntax:
if(condition):
statement
else:
statement
Program:
if num > 0:
print("Positive number")
else:
print("Negative number")
Output:
Enter a number: -7
Negative number
P.Shreya 19321A0596
Syntax:
if(condition):
statement
elif(condition):
statement
else:
statement
Program:
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
Output:
Enter a number: 0
Zero
P.Shreya 19321A0596
Syntax:
loop body
Program:
print(i)
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
Syntax:
loop body
Program:
sum = 0
sum = sum+val
Output:
Syntax:
while test_expression:
Body of while
Program:
i=1
print(i)
i += 2
Output:
11
13
15
P.Shreya 19321A0596
WEEK-4
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])
print(text.upper())
print("\nConverted String:lowercase")
print(text.lower())
print(text.title())
print("\nOriginal String")
print(text)
P.Shreya 19321A0596
Output:
llo
Converted String:lowercase
Converted String:
Original String
Program:
if number > 1:
if (number % i) == 0:
break
else:
else:
Output:
Program:
def Fibonacci(number):
if(number == 0):
return 0
elif(number == 1):
return 1
else:
print(Fibonacci(n))
Output:
3
P.Shreya 19321A0596
Program:
x, y = y, x
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
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!")
Enter number:67976
Program:
#print("Hello, World!")
print("Cheers, Mate!")
a=5
b = 10
c = a+b
Output:
Cheers, Mate!
Program:
sum = 0
temp = num
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
else:
Output: