Python Ex No-1& 2
Python Ex No-1& 2
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
Output:
Hello, GFG
<class 'str'>
add = num + 1
# Output
print(add)
Output
Enter a number:50
51
Taking List/Set elements one by one
List = list()
Set = set()
List.append(int(input()))
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.