Skip to content

QuickSort using lambda functions in one line #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: revert-114-pahad
Choose a base branch
from
41 changes: 41 additions & 0 deletions Code/calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This function adds two numbers
def add(x, y):
return x + y

# This function subtracts two numbers
def subtract(x, y):
return x - y

# This function multiplies two numbers
def multiply(x, y):
return x * y

# This function divides two numbers
def divide(x, y):
return x / y

print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

# Take input from the user
choice = input("Enter choice(1/2/3/4):")

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

if choice == '1':
print(num1,"+",num2,"=", add(num1,num2))

elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
else:
print("Invalid input")
8 changes: 8 additions & 0 deletions Code/division.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

firstnum = int(input("First number: "))
secondnum = int(input("Second number: "))

if secondnum == 0:
print("Division by zero illegal.")
else:
print("The result is " + str(firstnum/secondnum))
9 changes: 9 additions & 0 deletions Code/max2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Program to find maximum of 2 numbers
while 1:
n,m=map(int, raw_input())
k = max(m,n)
print k
print "Do you want to continue(yes/no): "
s=raw_input()
if s=="no":
break
22 changes: 22 additions & 0 deletions Code/palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# function which return reverse of a string
def reverse(s):
return s[::-1]

def isPalindrome(s):
# Calling reverse function
rev = reverse(s)

# Checking if both string are equal or not
if (s == rev):
return True
return False


# Driver code
s = raw_input("Enter the string:")
ans = isPalindrome(s)

if ans == 1:
print("Yes")
else:
print("No")
22 changes: 22 additions & 0 deletions Code/primeNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Python program to check if the input number is prime or not

num = 407

# take input from the user
# num = int(input("Enter a 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")
6 changes: 6 additions & 0 deletions Code/randomNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Program to generate a random number between 0 and 9

# import the random module
import random

print(random.randint(0,9))