Python File 1-9
Python File 1-9
Python File 1-9
AIM:
Write a program to demonstrate different number data types in Python.
Algorithm:
Step 1: Assign the value type to 3 types in any order.
Step 2: Print the 1st value using Type(_nameassignned).
Step 3: Print the 2nd value using Type(_nameassignned).
Step 4: Print the 3rd value using Type(_nameassignned).
Code:
Output:
Program-2
AIM:
Write a program to perform different arithmetic operations on numbers in python.
Algorithm:
Step3- Subtraction operation using - operator, a - b right hand operand from left hand operand.
Step5- Division operation using / operator, a / b divides left hand operand by right hand operand.
Step6- Floor Division operation using // operator, a // b divides left hand operand by right hand operand, here it
removes the values after decimal point.
Step7- Modulus % operator when applied returns the remainder when left hand operand is divided by right hand
operand a % b.
Code:
a=10
b=3
print("addition of a:",a,"&b:",b,"is:",a+b)
print("substraction of a:",a,"&b:",b,"is:",a-b)
print("multiplication of a:",a,"&b:",b,"is:",a*b)
print("division of a:",a,"&b:",b,"is:",a/b)
print("floor divison of a:",a,"&b:",b,"is:",a//b)
print("moduli of a:",a,"&b:",b,"is:",a%b)
print("exponent of a:",a,"&b:",b,"is:",a**b)
Output:
Program-3
AIM:
Write a program to create, concatenate and print a string and accessing sub-string from a given string.
Algorithm:
Step4- Then print the substring using from 1st word to the 4th word.
Code:
Output:
Program-4
AIM:
Write a python script to print the current date in the following format “Sun May 29 02:26:23 IST 2017”.
Algorithm:
Step 1: We be using the import library.
Step 2: Make a variable and assigning the local time to it.
Step 3: Printing the time using the syntax:(time.strftime("%a %b %d %H:%M:%S %Z
%Y",variable_name))
Code:
import time;
ltime=time.localtime();
print(time.strftime("%a %b %d %H:%M:%S %Z %Y",ltime)); #returns the formatted time
'''
%a : Abbreviated weekday name.
%b : Abbreviated month name.
%d : Day of the month as a decimal number [01,31].
%H : Hour (24-hour clock) as a decimal number [00,23].
%M : Minute as a decimal number [00,59].
%S : Second as a decimal number [00,61].
%Z : Time zone name (no characters if no time zone exists).
%Y : Year with century as a decimal number.'''
Output:
Program-5
AIM:
Write a program to create, append, and remove lists in python.
Algorithm:
Step 1: Creating the 2 lists.
Step 2: Print the two lists.
Step 3: Now adding the two lists to the another list which is empty.
Step 4: Now printing the new list.
Step 5: Now removing the element from the one original list.
Step 6: now printing the original list and the added list.
Code:
Output:
Program-6
AIM:
Write a program to demonstrate working with tuples in python.
Algorithm:
Step4- Now printing the element between 3rd element and 6th element.
Step6- Now checking if the given element is in the list and printing that element using syntax: ((len(T)).
Code:
Output:
Program-7
AIM:
Write a program to demonstrate working with dictionaries in python.
Code:
dict2=dict1.copy()
#New dictoinary
print("\n New Dictionary is :",dict2)
#empties the dictionary
dict1.clear()
print("\n Uadated Dictionary is :",dict1)
Output:
Program-8
AIM:
Write a python program to find largest of three numbers.
Algorithm:
Step2- using logic if 1st number is greater than second number and third number then it’s the greatest number.
Step3- and else if 2nd number is greater than the first and the third number then it’s the greatest number.
Code:
Output:
Program-9
AIM:
Write a Python program to convert temperatures to and from Celsius, Fahrenheit. [Formula: c/5 = f-32/9].
Code:
Output: