0% found this document useful (0 votes)
36 views4 pages

20bec024 Exp8

This document describes Experiment No. 8 which aimed to write Python programs to perform given tasks applying Python concepts. The experiment included tasks to create a simple calculator program, find the average of 5 numbers, and generate random binary numbers using Python's random module. The conclusion stated the experiment taught various Python data types, the random module, and identifying errors in transmitted bits. The document provides details of the experiment, including objectives, requirements, tasks and solutions, and conclusions.

Uploaded by

Dhruv Rathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

20bec024 Exp8

This document describes Experiment No. 8 which aimed to write Python programs to perform given tasks applying Python concepts. The experiment included tasks to create a simple calculator program, find the average of 5 numbers, and generate random binary numbers using Python's random module. The conclusion stated the experiment taught various Python data types, the random module, and identifying errors in transmitted bits. The document provides details of the experiment, including objectives, requirements, tasks and solutions, and conclusions.

Uploaded by

Dhruv Rathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment No.

8
Name: Dhruv Dholariya Roll No: 20BEC024
Date: 11/11/2021
Aim: Programming using Python

Objectives:
1. To write programs to perform the given task by applying Python
language concepts
Pre Lab Quiz:
1. Describe the various operators available in the Python
There are seven types of operators in python.
a) Arithmetic Operators: For basic arithmetic operations (+,-
,*,/)
b) Relational Operators: For comparison between two
variables (==,!=,<,>,<=,>=)
c) Assignment Operators: For assigning values to variables
(=,+=,*=,-=,/=,etc)
d) Logical Operators: For logical operations (and, or, not)
e) Membership Operators: For checking whether a value is
present in other given set of values (in, not in)
f) Identity Operators: For checking whether two values are
identical or not (is, is not)
g) Bitwise Operators: For bit by bit operation (&, |, ~, ^, <<,
>>)

Requirements:
Any installed Linux Distribution, any text editor, Python or any IDE like
anaconda-Spider
Python Installation:

• Linux− IDLE or Interactive terminal


• Use any text editor and write the Python code having extension
.py
• Run the Python file on the terminal using following command
$python3 filename.py

• Windows – Anaconda: Spider

• Macintosh − MacBinary or BinHex'd files.

B.Tech. Semester V 2ECDE55 Scripting Language


Task 1:
1. Simple Calculator

# Python program for simple calculator

# Function to add two numbers


def add(num1, num2):
return num1 + num2

# Function to subtract two numbers


def subtract(num1, num2):
return num1 - num2

# Function to multiply two numbers


def multiply(num1, num2):
return num1 * num2

# Function to divide two numbers


def divide(num1, num2):
return num1 / num2

print("Please select operation -\n" \


"1. Add\n" \
"2. Subtract\n" \
"3. Multiply\n" \
"4. Divide\n")

# Take input from the user


select = int(input("Select operations form 1, 2, 3, 4 :"))

number_1 = int(input("Enter first number: "))


number_2 = int(input("Enter second number: "))

if select == 1:
print(number_1, "+", number_2, "=",
add(number_1, number_2))

elif select == 2:
print(number_1, "-", number_2, "=",
subtract(number_1, number_2))

elif select == 3:
print(number_1, "*", number_2, "=",
multiply(number_1, number_2))

elif select == 4:
print(number_1, "/", number_2, "=",
divide(number_1, number_2))
else:
print("Invalid input")

B.Tech. Semester V 2ECDE55 Scripting Language


2. Finding Average of 5 number

# Python program to find average of five numbers

# take inputs
num1 = 2
num2 = 3
num3 = 6
num4 = 8
num5 = 10

# calculate average
avg = (num1 + num2 + num3 + num4 + num5) / 5

# print average value


print('The average of numbers = %0.2f' %avg)

Task 3 :-

import random
input = [0, 1]
e = random.choices(input, weights=(7/8,1/8), k=8)
strings = [str(i) for i in e]
a_string = "".join(strings)
e = int(a_string)
print("e =", e)

B.Tech. Semester V 2ECDE55 Scripting Language


Conclusion and Critical findings: From this experiment we learned about
numerous datatypes in Python and utilised them to construct code in this
exercise. Then we learned about Python's random module and used it to
produce random binary numbers with probability of 0 and 1 that were equal
and distinct. After that, we created code to identify errors in transmitted and
received bits.

Signature of Faculty Member:

B.Tech. Semester V 2ECDE55 Scripting Language

You might also like