From 39dd81b909207e87d4628263e5edaeb532731b8b Mon Sep 17 00:00:00 2001 From: Neha Reddy <92199778+nehareddies@users.noreply.github.com> Date: Sun, 15 Oct 2023 10:40:28 +0530 Subject: [PATCH] added codes --- Task2/DataStructures/Python/avg.py | 7 +++++++ Task2/DataStructures/Python/calc.py | 10 ++++++++++ Task2/DataStructures/Python/exchange.py | 4 ++++ Task2/DataStructures/Python/fibanocci.py | 12 ++++++++++++ Task2/DataStructures/Python/palindrome.py | 5 +++++ Task2/DataStructures/Python/sort_list.py | 13 +++++++++++++ 6 files changed, 51 insertions(+) create mode 100644 Task2/DataStructures/Python/avg.py create mode 100644 Task2/DataStructures/Python/calc.py create mode 100644 Task2/DataStructures/Python/exchange.py create mode 100644 Task2/DataStructures/Python/fibanocci.py create mode 100644 Task2/DataStructures/Python/palindrome.py create mode 100644 Task2/DataStructures/Python/sort_list.py diff --git a/Task2/DataStructures/Python/avg.py b/Task2/DataStructures/Python/avg.py new file mode 100644 index 0000000..ecd55f1 --- /dev/null +++ b/Task2/DataStructures/Python/avg.py @@ -0,0 +1,7 @@ +n = int(input("Enter number of elements : ")) +a = [] +for i in range(0,n): + elem = int(input("Enter a number : ")) + a.append(elem) +avg = sum(a)/n +print("The average is :", round(avg,2)) \ No newline at end of file diff --git a/Task2/DataStructures/Python/calc.py b/Task2/DataStructures/Python/calc.py new file mode 100644 index 0000000..f6347be --- /dev/null +++ b/Task2/DataStructures/Python/calc.py @@ -0,0 +1,10 @@ +text = input("Enter the string: ").lower() +vowels = sum(1 for a in text if a in 'aeiou') +consonants = sum(1 for a in text if a.isalpha() and a not in 'aeiou') +digits = sum(1 for a in text if a.isdigit()) +spaces = sum(1 for a in text if a.isspace()) + +print("Vowels:", vowels) +print("Consonants:", consonants) +print("Digits:", digits) +print("White spaces:", spaces) \ No newline at end of file diff --git a/Task2/DataStructures/Python/exchange.py b/Task2/DataStructures/Python/exchange.py new file mode 100644 index 0000000..d5dea86 --- /dev/null +++ b/Task2/DataStructures/Python/exchange.py @@ -0,0 +1,4 @@ +a = int(input("Enter value of a : ")) +b = int(input("Enter value of b : ")) +a,b = b,a +print("Exchanged values are : a is", a, "b is",b) \ No newline at end of file diff --git a/Task2/DataStructures/Python/fibanocci.py b/Task2/DataStructures/Python/fibanocci.py new file mode 100644 index 0000000..874fff9 --- /dev/null +++ b/Task2/DataStructures/Python/fibanocci.py @@ -0,0 +1,12 @@ +nterms = int(input("How many terms? ")) +n1, n2 = 0, 1 + +if nterms <= 0: + print("Please enter a positive integer") +elif nterms == 1: + print("Fibonacci sequence upto", nterms ,":") +else: + print("Fibonacci sequence:") + for _ in range(nterms): + print(n1) + n1, n2 = n2, n1 + n2 \ No newline at end of file diff --git a/Task2/DataStructures/Python/palindrome.py b/Task2/DataStructures/Python/palindrome.py new file mode 100644 index 0000000..b298743 --- /dev/null +++ b/Task2/DataStructures/Python/palindrome.py @@ -0,0 +1,5 @@ +a = input("Enter number/string to check if its palindrome : ") +if (a==a[::-1]): + print("The entered input is a palindrome!") +else : + print("The entered input is not a palindrome") \ No newline at end of file diff --git a/Task2/DataStructures/Python/sort_list.py b/Task2/DataStructures/Python/sort_list.py new file mode 100644 index 0000000..d85fa1d --- /dev/null +++ b/Task2/DataStructures/Python/sort_list.py @@ -0,0 +1,13 @@ +a = [] +c=[] +n1 = int(input("Enter number of elements: ")) +for i in range(1,n1+1): + b=int(input("Enter Element")) + a.append(b) +n2 = int(input("Enter number of elements: ")) +for i in range(1,n2+1): + d=int(input("Enter Element")) + c.append(d) +new=a+c +new.sort() +print("Sorted list is: ", new) \ No newline at end of file