0% found this document useful (0 votes)
8 views9 pages

Marketing Practical Programs in Python

Uploaded by

beheranirmal72
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)
8 views9 pages

Marketing Practical Programs in Python

Uploaded by

beheranirmal72
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

Name:- Sritam Behera

Class:- XI - C
Subject:- Business Studies
Topic:- Marketing(choosen
element:- Product)
Practical Programs Set 2

1. Write a program that reads a line and counts the number of uppercase, lowercase letters, digits
and symbols in it and displays them.

Code:-

s = input("Enter a line: ")

upper = 0

lower = 0

digit = 0

symbol = 0

for ch in s:

if [Link]():

upper += 1

elif [Link]():

lower += 1

elif [Link]():

digit += 1

else:

symbol += 1

print("Uppercase letters:", upper)

print("Lowercase letters:", lower)

print("Digits:", digit)

print("Symbols:", symbol)

output:-

Enter a line: my name is shivam and i am in class 11

Uppercase letters: 0

Lowercase letters: 27

Digits: 2

Symbols: 9
2. Write a program that reads a line and a substring and displays the number of occurrences of the
given substring within the string.

Code:-

s = input("Enter the string: ")

sub = input("Enter the substring: ")

count = [Link](sub)

print("Occurrences:", count)

output:-

Enter the string: do you know him, what do he do for living

Enter the substring: do

Occurrences: 3

3. Write a program that reads a string and displays it without the vowels.

Code:-

s = input("Enter a string: ")

result = ""

for ch in s:

if [Link]() not in "aeiou":

result += ch

print("String without vowels:", result)

output:-

Enter a string: do you know him

String without vowels: d y knw hm


4. Write a program that reads a line and displays the longest word in the line.

Code:-

line = input("Enter a line: ")

words = [Link]()

longest = words[0]

for word in words:

if len(word) > len(longest):

longest = word

print("Longest word:", longest)

output:-

Enter a line: my school name is saltlake shiksha niketan

Longest word: saltlake

5. Write a program that counts the frequency of a given element in a list of numbers.

Code:-

lst = [int(x) for x in input("Enter numbers: ").split()]

element = int(input("Enter element to find frequency: "))

count = [Link](element)

print("Frequency:", count)

output:-

Enter a list of numbers : [1,2,3,1,1,1]

Enter the element to find its frequency: 1

The frequency of 1 in the list is: 4


6. Write a program that takes a list of integers and creates two separate lists of posi ve and nega ve
integers.

Code:-

original_list = eval(input("Enter a list of integers (e.g., [10, -5, 0, 3, -1]): "))

pos_list = []

neg_list = []

for num in original_list:

if num >= 0:

pos_list.append(num) # Add to positive list (includes zero)

else:

neg_list.append(num) # Add to negative list

print("Positive integers list:", pos_list)

print("Negative integers list:", neg_list)

output:-

Enter a list of integers (e.g., [10, -5, 0, 3, -1]): [-1,-1,1,3,1,2,4]

Positive integers list: [1, 3, 1, 2, 4]

Negative integers list: [-1, -1]

7. Write a program that takes a list and an element and removes all occurrences of the given element
from the list.

Code:-

my_list = eval(input("Enter a list of elements (e.g., [1, 2, 3, 2, 4]): "))

element = eval(input("Enter the element to be removed: "))

while element in my_list:

my_list.remove(element)

print("Updated list after removal:", my_list)

output:-

Enter a list of elements (e.g., [1, 2, 3, 2, 4]): [1, 2, 3, 2, 4]

Enter the element to be removed: 1

Updated list after removal: [2, 3, 2, 4]


8. Write a program to input names of n students and store them in a tuple. Also input a name from
the user and finds if this student is present in the tuple or not.

Code:-

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

names = []

for i in range(n):

name = input("Enter name: ")

[Link](name)

students = tuple(names)

search = input("Enter name to search: ")

if search in students:

print("Student found")

else:

print("Student not found")

output:-

Enter number of students: 2

Enter name: shivam

Enter name: keshav

Enter name to search: keshav

Student found
9. Write a program that creates a tuple storing first 9 terms of Fibonacci series.

Code:-

a=0

b=1

fib_list = [a, b]

for i in range(7):

c=a+b

fib_list.append(c)

a=b

b=c

fib_tuple = tuple(fib_list)

print("The first 9 terms of the Fibonacci series are:")

print(fib_tuple)

output:-

The first 9 terms of the Fibonacci series are:

(0, 1, 1, 2, 3, 5, 8, 13, 21)

10. Write a program that creates a dictionary with details of n students, where roll no will be the key
and marks obtained will be the value. Now display the roll no of the student who has got the highest
marks.

Code:-

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

students = {}

for i in range(n):

roll = int(input("Enter roll number: "))

marks = int(input("Enter marks: "))f

students[roll] = marks

highest = max(students, key=[Link])

print("Roll number with highest marks:", highest)

output:-

Enter number of students: 3

Enter roll number: 31

Enter marks: 80
Enter roll number: 14

Enter marks: 70

Enter roll number: 25

Enter marks: 70

Roll number with highest marks: 31

11. Write a program that reads a sentence and create a dictionary that contains the letters/digits as
the keys and their frequency as the values.

Code:-

s = input("Enter a sentence: ")

freq = {}

for ch in s:

if ch != " ":

freq[ch] = [Link](ch, 0) + 1

print("Character frequency:", freq)

output:-

Enter a sentence: merry christmas to everyone

Character frequency: {'m': 2, 'e': 4, 'r': 4, 'y': 2, 'c': 1, 'h': 1, 'i': 1, 's': 2, 't': 2, 'a': 1, 'o': 2, 'v': 1, 'n': 1}

12. A dictionary D1 has values in the form of list of numbers. Write a program to create a new
dictionary D2 having the same keys as D1 but values as the sum of the list elements. e.g D1 = {‘A’ : [1,
2, 3], ‘B’ : [4, 5, 6]} ; then D2 is {‘A’ : 6, ‘B’ : 15}

Code:-

D1 = {'A': [1, 2, 3], 'B': [4, 5, 6]}

D2 = {}

for key in D1:

num_list = D1[key]

list_sum = sum(num_list)

D2[key] = list_sum
print("Original Dictionary (D1):", D1)

print("New Dictionary with Sums (D2):", D2)

output:-

Original Dictionary (D1): {'A': [1, 2, 3], 'B': [4, 5, 6]}

New Dictionary with Sums (D2): {'A': 6, 'B': 15}

You might also like