0% found this document useful (0 votes)
13 views5 pages

Python Programs With Outputs

The document provides Python programs for various tasks including finding maximum, minimum, and mean of numbers in lists and tuples, performing linear search, counting frequency of elements, and managing employee salary information. Each program includes sample inputs and outputs to demonstrate functionality. The examples cover both lists and tuples, as well as strings and dictionaries.

Uploaded by

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

Python Programs With Outputs

The document provides Python programs for various tasks including finding maximum, minimum, and mean of numbers in lists and tuples, performing linear search, counting frequency of elements, and managing employee salary information. Each program includes sample inputs and outputs to demonstrate functionality. The examples cover both lists and tuples, as well as strings and dictionaries.

Uploaded by

rishavsinha380
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Programs with Sample Inputs and Outputs

1. Finding Maximum, Minimum and Mean of Numbers in a List


numbers = list(map(int, input("Enter numbers separated by space: ").split()))

maximum = max(numbers)
minimum = min(numbers)
mean = sum(numbers) / len(numbers)

print("Maximum value:", maximum)


print("Minimum value:", minimum)
print("Mean value:", mean)

Example Input:
10 20 30 40 50

Output:
Maximum value: 50
Minimum value: 10
Mean value: 30.0

2. Linear Search on a List of Numbers


numbers = list(map(int, input("Enter numbers separated by space: ").split()))
search = int(input("Enter number to search: "))

found = False
for i in range(len(numbers)):
if numbers[i] == search:
print("Element found at position:", i)
found = True
break
if not found:
print("Element not found")
Example Input:
5 10 15 20
Search: 15

Output:
Element found at position: 2

3. Counting Frequency of Elements in a List


numbers = list(map(int, input("Enter numbers separated by space: ").split()))
freq = {}

for num in numbers:


if num in freq:
freq[num] += 1
else:
freq[num] = 1

for key in freq:


print(key, ":", freq[key])

Example Input:
1223334

Output:
1:1
2:2
3:3
4:1

4. Maximum, Minimum and Mean of Numbers in a Tuple


numbers = tuple(map(int, input("Enter numbers separated by space:
").split()))

maximum = max(numbers)
minimum = min(numbers)
mean = sum(numbers) / len(numbers)
print("Maximum value:", maximum)
print("Minimum value:", minimum)
print("Mean value:", mean)

Example Input:
10 20 30 40
Output:
Maximum value: 40
Minimum value: 10
Mean value: 25.0

5. Linear Search in a Tuple


numbers = tuple(map(int, input("Enter numbers separated by space:
").split()))
search = int(input("Enter number to search: "))

found = False
for i in range(len(numbers)):
if numbers[i] == search:
print("Element found at position:", i)
found = True
break

if not found:
print("Element not found")

Example Input:
5 10 15 20
Search: 15

Output:
Element found at position: 2

6. Frequency of Elements in a Tuple


numbers = tuple(map(int, input("Enter numbers separated by space:
").split()))
freq = {}

for num in numbers:


if num in freq:
freq[num] += 1
else:
freq[num] = 1

for key in freq:


print(key, ":", freq[key])

Example Input:
1223334

Output:
1:1
2:2
3:3
4:1

7. Count Frequency of Characters in a String using Dictionary


text = input("Enter a string: ")
freq = {}

for ch in text:
if ch in freq:
freq[ch] += 1
else:
freq[ch] = 1

for key in freq:


print(key, ":", freq[key])

Example Input:
hello
Output:
h:1
e:1
l:2
o:1

8. Employee Salary Dictionary Program


employees = {}

n = int(input("Enter number of employees: "))

for i in range(n):
name = input("Enter employee name: ")
salary = int(input("Enter salary: "))
employees[name] = salary

print(employees)
search = input("Enter employee name to check salary: ")

if search in employees:
print("Salary of", search, "is", employees[search])
else:
print("Employee not found")

Example Input:
2
Ravi 30000
Aman 40000
Search: Ravi

Output:
Salary of Ravi is 30000

You might also like