Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Monday, December 14, 2020

Get Search result in Python

 


def matchingWords(sentence1, sentence2):
    words1 = sentence1.strip().split(" ")
    words2 = sentence2.strip().split(" ")
    score = 0
    for word1 in words1:
        for word2 in words2:
            # print(f"Matchin word {word1} with {word2} ")
            if word1.lower() == word2.lower():
                score += 1
    return score


if __name__ == "__main__":
    # print(matchingWords("This is a good", "Python is a good"))
    sentences = ["Ashfaq is good boy",
                 "He work for Eaglesoft", "Eaglesoft is on of the best"]
    query = input("Please enter your query:\n")
    scores = [matchingWords(query, sentece) for sentece in sentences]
    # print(scores)
    sortSentScore = [sentScore for sentScore in sorted(
        zip(scores, sentences), reverse=True) if sentScore[0] != 0]
    # print(sortSentScore)
    print(f"{len(sortSentScore)} results found!\n")
    for score, item in sortSentScore:
        print(f" \"{item}\" with the score of {score}")

Sunday, December 13, 2020

Number guess game in Python with Eaglesoft Programmers

 


import random


def guessGame(a, b, num_random):
    guess = int(input(f"Guess a number between {a} to {b}:\n"))
    nguess = 1
    while guess != num_random:
        if guess < num_random:
            guess=int(input("Enter bigger!\n"))
            nguess += 1
        else:
            guess=int(input("Enter less!\n"))
            nguess += 1
    print(f"You guess the number in {nguess} attempt\n")
    return nguess


if __name__ == "__main__":
    a = int(input("Enter the value A"))
    b = int(input("Enter the value B"))
    num_random1 = random.randint(a, b)
    print("Player 1's is turn")
    g1 = guessGame(a, b, num_random1)
    print("Player 2's is turn")
    num_random2 = random.randint(a, b)
    g2 = guessGame(a, b, num_random2)
    if g1 < g2:
        print("Player 1 win!\n")
    elif g1 > g2:
        print("Player 2 win!\n")
    else:
        print("Tie!")
    print(f"Player 1 number is {num_random1} and Player 2 number is {num_random2} !\n")

Saturday, December 12, 2020

Find next palindrome in Python with Eaglesoft Programmers.


def next_palindrome(n):
    n=n+1
    while not is_palindrome(n):
        n += 1
    return n

def is_palindrome(n):
    return str(n)==str(n)[::-1]

if __name__ == "__main__":
    n=int(input("Enter the number of casese\n"))
    numbers=[]
    for i in range(n):
        number=int(input("Enter the number of that you want to find next palindrom\n"))
        numbers.append(number)

    for i in range(n):
        print(f"Next palindrome of {numbers[i]} is {next_palindrome(numbers[i])}")
    

Wednesday, December 2, 2020

Find divisor in python with Eaglesoft Programmers

 


n=int(input("Enter a number of apples:"))
mn=int(input("Enter minimum number:"))
mx=int(input("Enter maximum number"))
for i in range(mn,mx+1):
    if n%i==0:
        print(f"{i} is a divisor of {n}")
    else:
        print(f"{i} is not a divisor of {n}")


print("***This is Eaglesoft Programmer***")