-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4e9ca21
Showing
45 changed files
with
1,250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Name = input("Enter your Name : ") | ||
Branch = input("Tell me your Branch : ") | ||
Gender = input("what is your Gender : ") | ||
College = input("Enter your College Name : ") | ||
Age = int(input("Enter your Age : ")) | ||
|
||
print("Name: ",Name) | ||
print("Branch:",Branch) | ||
print("Gender:",Gender) | ||
print("College:",College) | ||
print("Age:",Age) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
number = float(input("Enter the number :")) | ||
square_root = number ** 2 | ||
print("square root of ",number , "is",square_root ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
a = int(input("Enter the value of a : ")) #3 | ||
b = int(input("Enter the value of b : ")) #4 | ||
a = a + b #a=7 ,b=4 | ||
b = a - b # b=3 ,a=7 | ||
a = a - b # a=4 ,b=3 | ||
|
||
print("After Swaping") | ||
print("Value of a =", a) | ||
print("Value of b =", b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cost_price = float(input("Enter the cost price of the product :")) | ||
sell_price = float(input("Enter the sell price of the product :")) | ||
profit = sell_price - cost_price | ||
NewSellingPrice = 1.05 * profit + cost_price | ||
print("The profit from this sell is " ,profit) | ||
print("To increase the profit by 5% the selling price should be ",NewSellingPrice) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Batsman1 = int(input("Enter the runs scored by first batsman in 60 balls: ")) | ||
Batsman2 = int(input("Enter the runs scored by second batsman in 60 balls: ")) | ||
Batsman3 = int(input("Enter the runs scored by third batsman in 60 balls: ")) | ||
|
||
Strikerate1 = Batsman1 * 100 / 60 | ||
Strikerate2 = Batsman2 * 100 / 60 | ||
Strikerate3 = Batsman3 * 100 / 60 | ||
|
||
print("strike rate of first batsman is ", Strikerate1) | ||
print("strike rate of second batsman is ", Strikerate2) | ||
print("strike rate of third batsman is ", Strikerate3) | ||
|
||
print("Runs scored by first batsman if they played 60 more balls is ", Batsman1 * 2) | ||
print("Runs scored by second batsman if they played 60 more balls is ", Batsman2 * 2) | ||
print("Runs scored by third batsman if they played 60 more balls is ", Batsman3 * 2) | ||
|
||
print("Maximum number of sixes of first batsman could hit =", Batsman1 // 6) | ||
print("Maximum number of sixes of second batsman could hit =", Batsman2 // 6) | ||
print("Maximum number of sixes of third batsman could hit =", Batsman3 // 6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# 1. odd/ even | ||
|
||
# To take input from the user | ||
num = int(input("Enter a number to check Odd/Even: ")) | ||
if (num % 2) == 0: | ||
print("{0} is Even".format(num)) | ||
else: | ||
print("{0} is Odd".format(num)) | ||
|
||
#---------------------------------------------------------------------------# | ||
|
||
# 2. Program to check if a number is prime or not | ||
|
||
# To take input from the user | ||
|
||
num = int(input("Enter a number to check Prime number: ")) | ||
|
||
# prime numbers are greater than 1 | ||
if num > 1: | ||
# check for factors | ||
for i in range(2,num): | ||
if (num % i) == 0: | ||
print(num,"is not a prime number") | ||
print(i,"times",num//i,"is",num) | ||
break | ||
else: | ||
print(num,"is a prime number") | ||
|
||
# if input number is less than | ||
# or equal to 1, it is not prime | ||
else: | ||
print(num,"is not a prime number") | ||
|
||
#---------------------------------------------------------------------------# | ||
|
||
# 3. Python program to check Palindrome | ||
|
||
# To take input from the user | ||
string=input(("Enter a string to check Palindrome:")) | ||
if(string==string[::-1]): | ||
print("The string is a palindrome") | ||
else: | ||
print("Not a palindrome") | ||
|
||
|
||
#---------------------------------------------------------------------------# | ||
|
||
|
||
# 4. Python program to check if the number is an Armstrong number or not | ||
|
||
# take input from the user | ||
num = int(input("Enter a number to check Armstrong number: ")) | ||
|
||
# initialize sum | ||
sum = 0 | ||
|
||
# find the sum of the cube of each digit | ||
temp = num | ||
while temp > 0: | ||
digit = temp % 10 | ||
sum += digit ** 3 | ||
temp //= 10 | ||
|
||
# display the result | ||
if num == sum: | ||
print(num,"is an Armstrong number") | ||
else: | ||
print(num,"is not an Armstrong number") | ||
|
||
|
||
#---------------------------------------------------------------------------# | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Program to display the Fibonacci sequence up to n-th term | ||
|
||
nterms = int(input("How many terms for Fibonacci sequence ? ")) | ||
|
||
# first two terms | ||
n1, n2 = 0, 1 | ||
count = 0 | ||
|
||
# check if the number of terms is valid | ||
if nterms <= 0: | ||
print("Please enter a positive integer") | ||
elif nterms == 1: | ||
print("Fibonacci sequence upto",nterms,":") | ||
print(n1) | ||
else: | ||
print("Fibonacci sequence:" ) | ||
while count < nterms: | ||
print(n1 , end= " ") | ||
nth = n1 + n2 | ||
# update values | ||
n1 = n2 | ||
n2 = nth | ||
count += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
# Program for star pattern | ||
|
||
n = int(input("Enter the value of N :")) | ||
for i in range(n): | ||
print (" " * i + "*" + " " * (n - 1 - i) + "*") | ||
for i in range(n): | ||
print(" " * (n - 1 - i) + "*" + " " * i + "*") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Program for star pattern | ||
|
||
n = int(input("Enter the value of N :")) | ||
for i in range(n): | ||
print ("* " *(n - i) + " " * i + " *" * (n - i) ) | ||
for i in range(2,n + 1): | ||
print("* " * i + " " *(n - i) + " *" *i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
# Program for pattern | ||
|
||
N = int(input("Enter the value of N :")) | ||
for i in range(N): | ||
print ((str(N - i) + "*") * (N - 1 - i) + str(N - i)) | ||
for i in range(2,N + 1): | ||
print((str(i) + "*") * (i - 1) + str(i)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
N = input("Enter a string : ") | ||
reverse = N[::-1] | ||
print("Now after given input ,the reverse string is : ") | ||
print(reverse) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
# program to find all permutation | ||
|
||
def permute(data, i, length): | ||
if i==length: | ||
print(''.join(data) ) | ||
else: | ||
for j in range(i,length): | ||
#swap | ||
data[i], data[j] = data[j], data[i] | ||
permute(data, i+1, length) | ||
data[i], data[j] = data[j], data[i] | ||
|
||
|
||
string = input("Enter the string for Permutation : ") | ||
n = len(string) | ||
data = list(string) | ||
permute(data, 0, n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def duplicate(string): | ||
duplicatestring = "" | ||
for i in string: | ||
if i not in duplicatestring: | ||
duplicatestring += i | ||
return duplicatestring | ||
string = input("Enter the string : ") | ||
print("After removing the duplicates , the string is : ", duplicate(string)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
# Program to remove duplicate from a List | ||
|
||
def duplicate(List): | ||
duplicateList = [] | ||
for n in List: | ||
if n not in duplicateList: | ||
duplicateList.append(n) | ||
return duplicateList | ||
|
||
size = int(input("Enter the no. of elements you want to add in list : ")) | ||
print("Enter the element in List one by one : ") | ||
List = [] | ||
for i in range(size): | ||
List.append(input()) | ||
print("List after removing the duplicates is : ",duplicate(List)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#Intersection of two lists | ||
def intertwolist(A, B): | ||
C = [i for i in A if i in B] | ||
return C | ||
# Driver Code | ||
A=list() | ||
B=list() | ||
n=int(input("Enter the size of the List ::")) | ||
print("Enter the Element of first list :: ") | ||
for i in range(int(n)): | ||
k=int(input("")) | ||
A.append(k) | ||
print("Enter the Element of second list :: ") | ||
for i in range(int(n)): | ||
k=int(input("")) | ||
B.append(k) | ||
print("THE FINAL LIST IS :: ",intertwolist(A, B)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
def Sum(List, size,sum): | ||
sumList = [] | ||
if size == 1: | ||
for x in List: | ||
sumList.append(sum + x) | ||
return sumList | ||
L2 = list(List) | ||
for x in List: | ||
L2.remove(x) | ||
sumList.extend(Sum(L2,size-1,sum + x)) | ||
return sumList | ||
|
||
def summation(List,size): | ||
sumList = list(List) | ||
for i in range (2, size + 1): | ||
sumList.extend(Sum(List,i,0)) | ||
number = 1 | ||
while True: | ||
if number not in sumList: | ||
print("The least integer which is not present in the list and also cannot be represented as the list : ") | ||
break | ||
number += 1 | ||
|
||
size = int(input("Enter the no. of elements you want to add in the list : ")) | ||
List = [] | ||
print("Enter the elements in list one by one .") | ||
for i in range(size): | ||
List.append(int(input())) | ||
summation(List, size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
# Count occurrences of an element | ||
|
||
str=input("Enter the string : ") | ||
word_count={char:str.count(char) for char in str} | ||
print(word_count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Python3 code to demonstrate working of | ||
# Sort tuple list by Nth element of tuple | ||
# using sort() + lambda | ||
|
||
# initializing list | ||
test_list = [(4, 5, 1), (6, 1, 5), (7, 4, 2), (6, 2, 4)] | ||
|
||
# printing original list | ||
print("The original list is : " + str(test_list)) | ||
|
||
# index according to which sort to perform | ||
N = 1 | ||
|
||
# Sort tuple list by Nth element of tuple | ||
# using sort() + lambda | ||
test_list.sort(key = lambda x: x[N]) | ||
|
||
# printing result | ||
print("List after sorting tuple by Nth index sort : " + str(test_list)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
#find second maximum value in dictionary | ||
|
||
#input | ||
example_dict = {"A":3, "B":15,"C":9,"D":19} | ||
|
||
# sorting the given list and get the second last element | ||
print(list(sorted(example_dict.values()))[-2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
student_data = {'id1': {'name': ['Sara'], 'class': ['V'], 'subject_integration': ['english, math, science'] }, | ||
'id2': {'name': ['David'], 'class': ['V'], 'subject_integration': ['english, math, science'] }, | ||
'id3': {'name': ['Sara'], 'class': ['V'], 'subject_integration': ['english, math, science']}, | ||
'id4': {'name': ['Surya'], 'class': ['V'], 'subject_integration': ['english, math, science']},} | ||
|
||
result = {} | ||
|
||
for key,value in student_data.items(): | ||
if value not in result.values(): | ||
result[key] = value | ||
|
||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Function to find winner of an election where votes | ||
# are represented as candidate names | ||
from collections import Counter | ||
|
||
def winner(input): | ||
|
||
# convert list of candidates into dictionary | ||
# output will be likes candidates = {'A':2, 'B':4} | ||
votes = Counter(input) | ||
|
||
# create another dictionary and it's key will | ||
# be count of votes values will be name of candidates | ||
|
||
dict = {} | ||
|
||
for value in votes.values(): | ||
|
||
# initialize empty list to each key to | ||
# insert candidate names having same | ||
# number of votes | ||
dict[value] = [] | ||
|
||
for (key,value) in votes.items(): | ||
dict[value].append(key) | ||
|
||
# sort keys in descending order to get maximum | ||
# value of votes | ||
maxVote = sorted(dict.keys(),reverse=True)[0] | ||
|
||
# check if more than 1 candidates have same | ||
# number of votes. If yes, then sort the list | ||
# first and print first element | ||
if len(dict[maxVote])>1: | ||
print( sorted(dict[maxVote])[0] ) | ||
else: | ||
print (dict[maxVote][0] ) | ||
|
||
# Driver program | ||
if __name__ == "__main__": | ||
input =['john','johnny','jackie','johnny','john','jackie','jamie','jamie', | ||
'john','johnny','jamie','johnny','john'] | ||
winner(input) |
Oops, something went wrong.