Link for downloading pycharm
https://www.jetbrains.com/pycharm/download/#section=windows
Troubleshooting link
https://www.jetbrains.com/help/pycharm/installation-guide.html
Practical 1: WAP to read and display the following information. Name, Address, Phone no.
def personal_details():
name, contact_no = "Simon", 7984272589
address = "Bangalore, Karnataka, India"
print("Name: {}\ncontact_no: {}\nAddress: {}".format(name,contact_no, address))
personal_details()
OUTPUT:
Name: Simon
contact_no: 7984272589
Address: Bangalore, Karnataka, India
Practical 2:WAP to read two numbers from the keyboard and display the larger one on the
screen.
print("Enter Two Numbers: ")
numOne = int(input())
numTwo = int(input())
if numOne>numTwo:
print("\nLargest Number =", numOne)
else:
print("\nLargest Number =", numTwo)
Output:
PRACTICAL 3: WAP to find, a given number is PRIME or NOT.
number = int(input("Enter any positive number:"))
if number<=1:
print(number, "is prime number")
if number>1:
for i in range(2,number):
if (number%i)==0:
print(number, "is not prime number")
break
else:
print(number, "is prime number")
Output:
PRACTICAL 4: WAP to swap two numbers.
n1 = int (input("Enter first number: "))
n2 = int (input("\nEnter second number: "))
print("Before swapping", (n1,n2))
temp = n1
n1=n2
n2=temp
print("After swapping", (n1,n2))
Output:
PRACTICAL 5: WAP to find factorial of a number.
n = int(input("Enter number:"))
fact = 1
i=1
for i in range (1,n+1):
fact = fact*i
print(fact)
Output:
PRACTICAL 6: WAP to print Fibonacci series of ‘n’ numbers, where n is given by the
programmer.
# Program to display the Fibonacci sequence up to n-th term
def fibo(x):
# first two terms
n1, n2 = 0, 1
count = 0
# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1, n2)
# generate fibonacci sequence
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
nterms = int(input("Enter a number to find fiboncci sequence: "))
fibo(nterms)
OUTPUT:
Practical 7: WAP to read a set of numbers in an array & to find the largest of them.
SOLUTION:
# function to find the Largest element of array
def FindLargestElement(arr,n):
maxVal = arr[0]
for i in range(1, n):
if arr[i] > maxVal:
maxVal = arr[i]
return maxVal
# code to take user input for the array...
n = int(input("Enter the number of elements in the array: "))
arr = []
print("Enter elements of the array: ")
for i in range(n):
numbers = int(input())
arr.append(numbers)
# Calling the method to find the largest value
maxVal = FindLargestElement(arr,n)
print ("Largest in given array is",maxVal)
Practical 8: WAP to sort a list of names in ascending order
num_array = list()
num = int(input("Enter how many names you want:"))
i=0
print ("Enter names in array:")
for i in range (i, num):
n = input("name :")
num_array.append (n)
print ('ARRAY: ',num_array)
num_array.sort()
print("Sorted Names:",num_array)
Output:
Practical 9: WAP to read a set of numbers from keyboard & to find the sum of all elements
of the given array using a function.
def _sum(arr,n):
# return sum using sum
# inbuilt sum() function
return(sum(arr))
# driver function
arr=[]
# input values to list
arr = [32,45,12,6]
# calculating length of array
n = len(arr)
ans = _sum(arr,n)
# display sum
print ('Sum of the array is ',ans)
OUTPUT:
Practical 10: Calculate area of different geometrical figures (circle, rectangle, square, and
triangle)
SOLUTION:
def calculate_area(name):\
# converting all characters
# into lower cases
name = name.lower()
# check for the conditions
if name == "rectangle":
l = int(input("Enter rectangle's length: "))
b = int(input("Enter rectangle's breadth: "))
# calculate area of rectangle
rect_area = l * b
print(f"The area of rectangle is {rect_area}.")
elif name == "square":
s = int(input("Enter square's side length: "))
# calculate area of square
sqt_area = s * s
print(f"The area of square is {sqt_area}.")
elif name == "triangle":
h = int(input("Enter triangle's height length: "))
b = int(input("Enter triangle's breadth length: "))
# calculate area of triangle
tri_area = 0.5 * b * h
print(f"The area of triangle is {tri_area}.")
elif name == "circle":
r = int(input("Enter circle's radius length: "))
pi = 3.14
# calculate area of circle
circ_area = pi * r * r
print(f"The area of circle is {circ_area}.")
elif name == 'parallelogram':
b = int(input("Enter parallelogram's base length: "))
h = int(input("Enter parallelogram's height length: "))
# calculate area of parallelogram
para_area = b * h
print(f"The area of parallelogram is {para_area}.")
else:
print("Sorry! This shape is not available")
# driver code
if __name__ == "__main__" :
print("Calculate Shape Area")
shape_name = input("Enter the name of shape whose area you want to find: ")
# function calling
calculate_area(shape_name)
OUTPUT 1:
OUTPUT 2:
Practical 11: WAP to increment the employee salaries on the basis of their designation
(Manager-5000, General Manager-10000, CEO-20000, worker-2000). Use employee name,
id, designation and salary as data member and inc_sal as member function
SOLUTION:
#this is sample code for calculating the increment.
#create a function and implement this code
oldSalaryPerMonth = int(input("Enter your old salary per month:"))
hike = int(input("Enter your hike percentage:"))
presentSalaryPerMonth = oldSalaryPerMonth + (oldSalaryPerMonth * hike / 100)
print("After hike your present salary per month is: ", presentSalaryPerMonth)
Practical 12: WAP to read data from keyboard & write it to the file. After writing is
completed, the file is closed. The program again opens the same file and reads it.
# Program to show various ways to read and
# write data in a file.
file1 = open("myfile.txt","w")
L = ["This is Delhi \n","This is Paris \n","This is London \n"]
# \n is placed to indicate EOL (End of Line)
file1.write("Hello \n")
file1.writelines(L)
file1.close() #to change file access modes
file1 = open("myfile.txt","r+")
print("Output of Read function is ")
print(file1.read())
print()
# seek(n) takes the file handle to the nth
# bite from the beginning.
file1.seek(0)
print( "Output of Readline function is ")
print(file1.readline())
print()
file1.seek(0)
# To show difference between read and readline
print("Output of Read(9) function is ")
print(file1.read(9))
print()
file1.seek(0)
print("Output of Readline(9) function is ")
print(file1.readline(9))
file1.seek(0)
# readlines function
print("Output of Readlines function is ")
print(file1.readlines())
print()
file1.close()
Output:
Output of Read function is
Hello
This is Delhi
This is Paris
This is London
Output of Readline function is
Hello
Output of Read(9) function is
Hello
Th
Output of Readline(9) function is
Hello
Output of Readlines function is
['Hello \n', 'This is Delhi \n', 'This is Paris \n', 'This is
London \n']