0% found this document useful (0 votes)
4 views

taufikpy

The document contains a series of practical exercises in Python programming, covering various topics such as basic input/output, mathematical operations, control structures, and data structures like lists, tuples, and sets. Each practical includes code snippets that demonstrate specific functionalities, such as calculating areas, converting units, and manipulating data structures. The exercises aim to enhance programming skills through hands-on practice.

Uploaded by

sktaufik7860
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

taufikpy

The document contains a series of practical exercises in Python programming, covering various topics such as basic input/output, mathematical operations, control structures, and data structures like lists, tuples, and sets. Each practical includes code snippets that demonstrate specific functionalities, such as calculating areas, converting units, and manipulating data structures. The exercises aim to enhance programming skills through hands-on practice.

Uploaded by

sktaufik7860
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Practical No 1:

Exercise:

1]

import sys

print(sys.version)
Practical No 2:

Exercise:

1]

print(“Taufique”)

Taufique
Taufique

2]

print(“MSBTE)
Practical No 3:

Exercise:

1]

print("Conversion of US dollar into Indian Rupees Note:1$=70INR")

USDollar=int(input("Enter Dollar Amount ="))

INR = USDollar*71.27

print("INR =",INR)

2]

print("Conversioin of Bites to MB,GB,TB")

bits = int(input("Enter number of bits"))

byte = bits/8

kb = byte/1024

mb = kb/1024

gb = mb/1024

tb = gb/1024

print("Megabites =",mb)

print("Gigabites =",gb)

print("Terabites =",tb)
3]

import math

print("Finding Square root of a number")

no = int(input("Enter Number"))

squareRoot = math.sqrt(no)

print("Square root =",squareRoot)

4]

print("Calculating Area Of Rectangle")

length = int(input("Enter length="))

breadth=int(input("Enter breadth="))

print("Area=",(length*breadth))
5] import math

print("Calculating Area and perimeter of Square")

s = int(input("Enter side="))

print("Area =",s*s)

print("Perimeter =",(4*s))

6]

print("Calculating area and volume of cylender")

pi = 3.14

r = int(input("Enter Radius ="))

h = int(input("Enter height ="))

print("Volume =",pi*(r*r))

print("Area =",(2*pi*r*h+2*pi*(r*r)))
7]

print("Swapping 2 Numbers")

no1 = int(input("Enter 1st no="))

no2 = int(input("Enter 2nd no="))

temp = no1

no1 = no2

no2 = temp

print("1st number =",no1)

print("2nd number =",no2)


Practical No 4:

Exercise:

1]

print("check whether the number is even or odd")

num = int(input("Enter a number: "))

if num % 2 == 0:

print("Even")

else:

print("Odd")

2]

print("Find the absolute value of the number")

no = int(input("Enter Number:"))

print("Absolute value of",no,"=",abs(no))


3]

num1 = float(input("Enter the first number: "))

num2 = float(input("Enter the second number: "))

num3 = float(input("Enter the third number: "))

if num1 >= num2 and num1 >= num3:

print(f"The largest number is {num1}")

elif num2 >= num1 and num2 >= num3:

print(f"The largest number is {num2}")

else:

print(f"The largest number is {num3}")

4]

year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):

print(f"{year} is a leap year.")

else:

print(f"{year} is not a leap year.")


5]

num = float(input("Enter a number: "))

if num > 0:

print("The number is positive.")

elif num < 0:

print("The number is negative.")

else:

print("The number is zero.")

6]

# Input marks for 5 subjects

marks = [float(input(f"Enter marks for subject {i+1}: ")) for i in range(5)]

# Calculate average

average = sum(marks) / 5

# Determine grade

if average >= 90:

grade = "A"

elif average >= 80:

grade = "B"

elif average >= 70:

grade = "C"

elif average >= 60:

grade = "D"
else:

grade = "F"

# Display grade

print(f"Your grade is {grade}.")


Practical No 5

Practical Related Questions

1]

x=10

while x>5:

print x

x-=1

2]

x=1

while x < 10:

print (x),

x+=1
Exercise

a]

for i in range(1, 5):

print("*" * i)

b]

n = 3 # Size of the diamond (half the height)

# Upper part of the diamond

for i in range(1, n + 1):

print(" " * (n - i) + "*" * (2 * i - 1))

# Lower part of the diamond

for i in range(n - 1, 0, -1):

print(" " * (n - i) + "*" * (2 * i - 1))


c]

n = 4 # Number of rows

for i in range(n):

spaces = " " * i

numbers = "1" + "01" * (n - i - 1)

print(spaces + numbers)

2]

num = 2 # Start from the first even number

while num <= 100:

print(num)

num += 2 # Increment by 2 to get the next even number


3]

sum_of_numbers = 0

for num in range(1, 11):

sum_of_numbers += num

print("The sum of the first 10 natural numbers is:", sum_of_numbers)

4]

n = int(input("Enter the number of terms: "))

a, b = 0, 1

for _ in range(n):

print(a, end=" ")

a, b = b, a + b
5]

num = int(input("Enter a number: "))

factorial = 1

for i in range(1, num + 1):

factorial *= i

print(f"The factorial of {num} is {factorial}")

6]

num = int(input("Enter a number: "))

reversed_num = 0

while num > 0:

digit = num % 10

reversed_num = reversed_num * 10 + digit

num = num // 10

print(f"The reversed number is {reversed_num}")


7]

num = input("Enter a number: ")

sum_digits = sum(int(digit) for digit in num)

print(f"The sum of the digits is: {sum_digits}")

8]

num = input("Enter a number: ")

if num == num[::-1]:

print(f"{num} is a palindrome.")

else:

print(f"{num} is not a palindrome.")


Practical no 6]

Exercise:

1]

numbers = [1, 2, 3, 4, 5]

total = sum(numbers)

print(f"The sum of all items in the list is: {total}")

2]

# List of numbers

numbers = [1, 2, 3, 4, 5]

product = 1

for num in numbers:

product *= num

print(f"The product of all items in the list is: {product}")


3]

numbers = [1, 2, 3, 4, 5]

largest_number = max(numbers)

print(f"The largest number in the list is: {largest_number}")

4]

numbers = [1, 2, 3, 4, 5]

smallest_number = min(numbers)

print(f"The smallest number in the list is: {smallest_number}")

5]

numbers = [1, 2, 3, 4, 5]

reversed_list = numbers[::-1]

print(f"The reversed list is: {reversed_list}")


6]

list1 = [1, 2, 3, 4, 5]

list2 = [4, 5, 6, 7, 8]

common_items = list(set(list1) & set(list2))

print(f"The common items between the two lists are: {common_items}")

7]

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

even_items = [num for num in numbers if num % 2 == 0]

print(f"The even items in the list are: {even_items}")


Practical No 7:

Exercise:

1]

numbers = (10, 20, 30, 40, 50)

min_num = min(numbers)

max_num = max(numbers)

print(f"The minimum number in the tuple is: {min_num}")

print(f"The maximum number in the tuple is: {max_num}")

2]

numbers = (1, 2, 3, 4, 5, 2, 3, 6, 7, 3)

repeated_items = []

for num in numbers:

if numbers.count(num) > 1 and num not in repeated_items:

repeated_items.append(num)

print(f"The repeated items in the tuple are: {repeated_items}")


3]

def number_to_words(num):

num_dict = {

'0': 'Zero', '1': 'One', '2': 'Two', '3': 'Three',

'4': 'Four', '5': 'Five', '6': 'Six', '7': 'Seven',

'8': 'Eight', '9': 'Nine'

num_str = str(num)

words = [num_dict[digit] for digit in num_str]

return ' '.join(words)

num = int(input("Enter a number: "))

print(f"The number {num} in words is: {number_to_words(num)}")


Practical No 8:

Exercise:

1]

my_set = {1, 2, 3}

my_set.add(4)

my_set.update([5, 6])

my_set.remove(3)

print(f"The modified set is: {my_set}")

2]

set1 = {1, 2, 3, 4}

set2 = {3, 4, 5, 6}

print(f"Intersection: {set1 & set2}")

print(f"Union: {set1 | set2}")

print(f"Difference: {set1 - set2}")

print(f"Symmetric Difference: {set1 ^ set2}")

set1.clear()

print(f"Set1 after clear: {set1}")


3]

my_set = {10, 20, 30, 40, 50}

print(f"Maximum value: {max(my_set)}")

print(f"Minimum value: {min(my_set)}")

4]

my_set = {10, 20, 30, 40, 50}

print(f"Length of the set: {len(my_set)}")

You might also like