0% found this document useful (1 vote)
27 views

Python Ex No-1& 2

The document describes two Python programs. The first program takes user input in various forms like strings, integers, lists and sets. It demonstrates input and output functions. The second program defines a function to find the median of three numbers. It takes three numbers as input from the user and displays their median by using if-else statements to check conditions. Both programs execute successfully to demonstrate input, output, functions and control flow statements in Python.

Uploaded by

Poovarasan R
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
27 views

Python Ex No-1& 2

The document describes two Python programs. The first program takes user input in various forms like strings, integers, lists and sets. It demonstrates input and output functions. The second program defines a function to find the median of three numbers. It takes three numbers as input from the user and displays their median by using if-else statements to check conditions. Both programs execute successfully to demonstrate input, output, functions and control flow statements in Python.

Uploaded by

Poovarasan R
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Ex No:1 PYTHON PROGRAM USING INPUT AND OUTPUT FUNCTIONS

AIM:
To write a python program using input and output function.

ALGORITHM:
1. Step 1: Start the program.
2. Step 2: Declare the variables and get the input in various forms.
3. Step 3: Get the input and append in the list.
4. Step 4: Print the output.
5. Step 5: Stop the program.
Program
Python get user input with a message

# Taking input from the user


name = input("Enter your name: ")
# Output
print("Hello, " + name)
print(type(name))

Output:

Enter your name: GFG

Hello, GFG

<class 'str'>

Integer input in Python 

# Taking input from the user as integer

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

add = num + 1

# Output
print(add)

Output
Enter a number:50
51
Taking List/Set elements one by one

List = list()

Set = set()

l = int(input("Enter the size of the List : "))

s = int(input("Enter the size of the Set : "))

print("Enter the List elements : ")

for i in range(0, l):

List.append(int(input()))

print("Enter the Set elements : ")

for i in range(0, s):

Set.add(int(input()))

print(List)

print(Set)

Output:
Enter the size of the List : 4
Enter the size of the Set : 3
Enter the List elements :
9
0
1
3
Enter the Set elements :
2
9
1
[9, 0, 1, 3]
{9, 2, 1}
Using map() and list() / set() Methods
List = list(map(int, input("Enter List elements : ").split()))
Set = set(map(int, input("Enter the Set elements :").split()))
print(List)
print(Set)
Output
Enter List elements : 3 4 8 9 0 11
Enter the Set elements :34 88 230 234 123
[3, 4, 8, 9, 0, 11]
{34, 230, 234, 88, 123}

Result
Thus, the program of input and output function has been executed
successfully.
Ex.No:2 PYTHON PROGRAM USING LOOPING AND FUNCTION

AIM:
To write python program using control flow statement and functions.Write a function
that takes three numbers as parameters, and returns the median value of those parameters as
its result. Include a main program that reads three values from the user and displays their
median.
ALGORITHM:
Step 1: Start the program.
Step 2: Declare the variables.
Step 3: Check the condition to find the median by using the if else statement.
Step 4: Print the output.
Step 5: Stop the program.
Program
def median():
a = int(input())
b = int(input())
c = int(input())
if a > b:
if a < c:
median = a
elif b > c:
median = b
else:
median = c
else:
if a > c:
median = a
elif b < c:
median = b
else:
median = c
print(median)
median()

OUTPUT:

Result
Thus, the python program using control flow statement and functions has been
executed successfully.

You might also like