Python File
Python File
Code:
num1=10
num2=45.56
num3=complex(a,b)
print("Type of num1 is:", type(num1))
print("Type of num2 is:", type(num2))
print("Type of num3 is:", type(num3))
Output:
Code:
Output:
Aim: Write a program to create, concatenate and print a string and accessing sub-
string from a given string.
Code:
Concatenate=Str1+ “” +Str2
Output:
Aim: Write a python script to print the current date in the following format “Sun
May 29 02:26:23 IST 2017”
Code:
import time
ltime=time.localtime();
print(ltime)
Output:
Code:
a=[1,78,20,"Python"]
a.append(98)
a.remove(78)
list=[1,"asia",3.2,"cup"]
list.append (2023)
print(list)
list.remove(3.2)
print(list)
Output:
Output:
Code:
fahrenheit = celsius*(9/5)+32
celsius=(f-32 )* 5/9
Output:
Aim: Write a Python program to construct the following pattern, using a nested for
loop .
Code:
n=4
print(" ")
print(" ")
print("*")
Output:
Experiment Title: Write a Python script that prints prime numbers less than
20
Aim: Write a Python script that prints prime numbers less than 20.
Code:
def is_prime(number):
if number <= 1:
return False
if number <= 3:
return True
if number % 2 == 0 or number % 3 == 0:
return False
i=5
if number % i == 0 or number % (i + 2) == 0:
return False
i += 6
return True
def print_primes_less_than_20():
if is_prime(num):
print(num)
print_primes_less_than_20()
Output:
def recur_fact(n):
if n==1:
return n
else:
return n*recur_fact(n-1)
num=int (input("enter a number: "))
if num<0:
print("sorry, factorial does not exist for negative numbers")
elif num==0:
print("the factorial of 0 is 1")
else:
print("the factorial of ", num,"is", recur_fact(num))
Output:
Aim: Write a program that accepts the lengths of three sides of a triangle as inputs.
The program output should indicate whether or not the triangle is a right triangle
(Recall from the Pythagorean Theorem that in a right triangle, the square of one side
equals the sum of the squares of the other two sides).
Code:
Output:
Aim: Write a python program to define a module to find Fibonacci Numbers and
import the module to another program.
Code:
Module file:
def fib(num):
f1= 0
f2=1
for i in range(num):
f3=f1+f2
f1=f2
f2=f3
Main file:
import fib
n=int(input("Enter number:"))
fib.fib(n)
Output:
Aim: Write a python program to define a module and import a specific function in
that module to another program.
def sub(a,b):
c=a-b
return c
def add(a,b):
c=a+b
return c
3. Main file:
import sub
import add
num1= int(input("enter first number"))
num2= int(input("enter second number"))
print("subtraction of two numbers is:",sub.sub(num1,num2))
print("addition of two numbers is:", add.add(num1,num2))
Output:
Aim: Write a script named copyfile.py. This script should prompt the user for the
names of two text files. The contents of the first file should be input and written to
the second file.
Code:
Output:
Experiment Title:
Experiment Title:
Experiment Title:
Experiment Title: