Find the best tutors and institutes for Python Training

Find Best Python Training classes

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Outside India?

Search for topics

Python Training Updates

Ask a Question

Post a Lesson

All

All

Lessons

Discussion

Lesson Posted on 16 Nov IT Courses/Programming Languages/Python

Build an interactive Dictionary using Python 3.x

Biswanath Banerjee

I have 20 years of solid technology experience , worked in various IT MNCs like IBM, Tech Mahindra, AT&T,...

I have downloaded a 5MB data base consisting of words and their meanings in a json file . I want to write a python progrsm which will ask the user to enter a word and then the program will search through the database and retuen back the meaning of the word . There can be instances when there are two... read more

 I have downloaded a 5MB data base consisting of words and their meanings in a json file . I want to write a python progrsm which will ask the user to enter a word and then the program will search through the database and retuen back the meaning of the word . There can be instances when there are two or three different meanings for a word. The program will display all the different meanings of the word.

I wanted to make the program little intelligent. What if the user spells he word incorrectly while entering the word? Suppose he wants to know the meaning of 'crowd' but by mistake he types in 'crowded'. The system will be intelligent enough to suggest few words nearest to the word 'crowdd' which he has typed and let the user choose the right word which he meant from the list of suggesstions.

Also , there are checks for cases - upper case, lower case etc.

Let us see the code now and then run the program to see the outputs:

Here is the python code which you have been eaiting for so long:

import json
from difflib import get_close_matches

data = json.load(open("data.json"))

print(data)

def translate(w):
w = w.lower()
if w in data:
return data[w]
if w in data:
return data[w]
elif w.title() in data: # user entered "maryland" will check for "Maryland" as well
return data[w.title()]
elif w.upper() in data:
return data[w.upper()]
elif len(get_close_matches(w,data.keys()))>0:
yn= input("Did you mean %s instead?. EnterY if yes, or N if no: "% get_close_matches(w,data.keys())[0])
if yn=='Y':
return data[get_close_matches(w,data.keys())[0]]
elif yn =='N':
return("the word does not exist")

else:
return ('We did not understand your entry')
else:
return("the word does not exist")
word = input("Enter word")
output =translate(word)
if type(output) == list:
for item in output:
print(item)
else:
print(output)

Let us test out different scenarios now :

Input: data["crowd"]

Output: ['A large number of people united for some specific purpose.', 'A crowd of people pressed close together in a small space.', '6-string musical instrument of Welsh or Irish origin and played with a bow.', 'A large group of people.', 'To cause to herd, drive, or crowd together.', 'To fill or occupy in a small space to the point of overflowing.', 'To gather together in large numbers.']

Input:

Enter word crowdd
Output:Did you mean crowded instead?. EnterY if yes, or N if no: 
Input: N
Output: the word does not exist

Another scenario. Suppose the User does not type the whole word but abbreviation like 'USA' or 'UK'.
How does our dictionary program find out the meaning in such case?
Input: Let us try out: Enter word UK
Output: A country in Western Europe (comprising Wales, Scotland, England and Northern Ireland) with the capital London.

This is a simple program to show you how to write simple Applications using Python.
Stay tuned to my Lessons. Next Lesson I will show you how to write another interesting interactive application
using Python.
read less
Comments
Dislike Bookmark

Answered on 02 Dec IT Courses/Programming Languages/Python

Pramod M.

Python trainer who trained around 500 students and help them secure a job

Python is best language to start with...ease of coding and reading in python makes amateur programmer like you to understand the concepts of programming....but my suggestion is dont learn just to learn it I mean do not learn the theory aspects learn the practical aspects like applying the concepts and... read more

Python is best language to start with...ease of coding and reading in python makes amateur programmer like you to understand the concepts of programming....but my suggestion is dont learn just to learn it I mean do not learn the theory aspects learn the practical aspects like applying the concepts and get 2 mini projects done in python because that is how many of our ECE students got jobs in TCS and Wipro.

read less
Answers 6 Comments
Dislike Bookmark

Answered 4 days ago IT Courses/Programming Languages/Python

How can I print perfect numbers in a given range in Python?

Gayathri J.

def print_perfect_nums(start, end): for i in range(start, end + 1): sum1 = 0 for x in range(1, i): # Check if a divisor, if it is, add to sum if(i % x == 0): sum1 = sum1 + x if (sum1 == i): print(i) print_perfect_nums(1, 300)Perfect number is sum of... read more
def print_perfect_nums(start, end):
   for i in range(start, end + 1):
   sum1 = 0
   for x in range(1, i):
      # Check if a divisor, if it is, add to sum
      if(i % x == 0):
         sum1 = sum1 + x
         if (sum1 == i):
            print(i)
print_perfect_nums(1, 300)

Perfect number is sum of the divisorsa of the number is equal to the same number eg 6 divisors
are 1,2,3
read less
Answers 1 Comments
Dislike Bookmark

Looking for Python Training classes

Find best Python Training classes in your locality on UrbanPro.

FIND NOW

Answered on 26 Nov IT Courses/Programming Languages/Python

Which is the best book for the Python OOPS concept?

Joshua

Tutor

The best book you can read is by O”Reilly
Answers 1 Comments
Dislike Bookmark

Answered on 13 Nov IT Courses/Programming Languages/Python

How can I write a Python program to check if a string is a palindrome or not without reversing the original string?

Michael Devine

ENHANCE YOUR SKILL SET WITH QUICK COURSES

By reversing, the rhs will return the reverse of the string. >>> s='malayalam'>>> 'is a palindrome' if s==s else 'not a palindrome''is a palindrome'>>> >>> s=input('enter a string... ')enter a string... racecar>>> 'is a palindrome' if s==s else 'not a palindrome''is... read more

By reversing, the rhs will return the reverse of the string.

>>> s='malayalam'
>>> 'is a palindrome' if s==s[::-1] else 'not a palindrome'
'is a palindrome'
>>> 
>>> s=input('enter a string... ')
enter a string... racecar
>>> 'is a palindrome' if s==s[::-1] else 'not a palindrome'
'is a palindrome'
>>> s=input('enter a string... ')
enter a string... a string
>>> 'is a palindrome' if s==s[::-1] else 'not a palindrome'
'not a palindrome'
>>>

_______________________________________________________________________________

Otherwise, you can check each character in the string read from the front against each character read from the back..

>>> s='malayalam'
>>> for i in range(len(s)):
             if s[i]!=s[-(i+1)]:
                    'not a palindrome'
                    break
             else: None
else: 'is a palindrome'

'is a palindrome'
>>> s='rotor'
>>> for i in range(len(s)):
              if s[i]!=s[-(i+1)]:
                    'not a palindrome'
                     break
              else: None
else: 'is a palindrome'

'is a palindrome'
>>> s='qwerty'
>>> for i in range(len(s)):
              if s[i]!=s[-(i+1)]:
                    'not a palindrome'
                     break
              else: None
else: 'is a palindrome

'not a palindrome'
>>>

read less
Answers 1 Comments
Dislike Bookmark

Answered on 14 Nov IT Courses/Programming Languages/Python

Is there any way to completely hide a variable in Python?

Michael Devine

ENHANCE YOUR SKILL SET WITH QUICK COURSES

What is a Variable: In Python, a variable is just a reference to a Python Object. There will always be a single instance of any particular Python object in the Python memory. Multiple variables will refer to the same object if defined or generated. Deletion of the reference is handled by the 'del' command.... read more

What is a Variable: In Python, a variable is just a reference to a Python Object. There will always be a single instance of any particular Python object in the Python memory. Multiple variables will refer to the same object if defined or generated. Deletion of the reference is handled by the 'del' command. The object itself is not removed from the mempry by the garbage collector if other references to it exist. 

Hiding a variable: Now, this could be in reference to private variables. Well, private variables are visible in Python objects. However, if you really want to hide a variable, then, a closure is the best option. Any other form of scope will also hide a variable.

read less
Answers 2 Comments
Dislike Bookmark

Looking for Python Training classes

Find best Python Training classes in your locality on UrbanPro.

FIND NOW

Answered on 14 Nov IT Courses/Programming Languages/Python

What are decorators in Python?

Michael Devine

ENHANCE YOUR SKILL SET WITH QUICK COURSES

The general method for the reuse of functionality in object-oriented programming is inheritance through a class hierarchy. A decorator provides a way to define functionality that's not bound to the inheritance hierarchy. The Pythonic approach to aspect-oriented programming (AOP) involves decorators.... read more

The general method for the reuse of functionality in object-oriented programming is inheritance through a class hierarchy. A decorator provides a way to define functionality that's not bound to the inheritance hierarchy. The Pythonic approach to aspect-oriented programming (AOP) involves decorators. Python comes with many decorators.

read less
Answers 2 Comments
Dislike Bookmark

Answered on 11 Nov IT Courses/Programming Languages/Python

Who do Python developers have a higher salary than PHP developers?

Akhlaque Khan

Java Corporate Trainer

Python is playing valuable role in IoT and Machine Learning and which bringing revolution in technologies and hence but obviously...
Answers 1 Comments
Dislike Bookmark

Answered on 12 Nov IT Courses/Programming Languages/Python

How do I do this in Python: for (I=0, j=n; I=0; I++, j--)?

Michael Devine

ENHANCE YOUR SKILL SET WITH QUICK COURSES

There may be a typo in the question. however this could be the corrected question..... for (I=0, j=n; I<n; I++, j--) >>> # for (I=0, j=n; I<n; I++, j--)>>> j=n=10 # we initialize 'n' and 'j'>>> # i<10 is the terminating condition, so we loop 'n' times. >>>... read more

There may be a typo in the question. however this could be the corrected question.....

for (I=0, j=n; I<n; I++, j--)

 

>>> # for (I=0, j=n; I<n; I++, j--)
>>> j=n=10    # we initialize 'n' and 'j'
>>> # i<10 is the terminating condition, so we loop 'n' times. 
>>> for i in range(n):
              #in your case you are incrementing i by 1 repeatedly
              #and in the end i==n. j will be decremented by 1, n times.
              #In Python, we simulate the 'for' loop with range() and the the Range object will have a
              #sequence of int objects from 0 to 9. (ie.n-1). The 'for' construct will iterate thru the 
              #Range object according to its size and stop,after which it will execute the 'else' block. 
              #In Python, 'else' is an independent construct that can be used when ever a condition is checked.
              #'else' will execute when a condition is 'False'. We initialize 'n' and 'j' outside the 'for' construct.
              #The range() will construct a Range object of ints from 0 to n. All we need to do is decrement j.
              #On successful completion of the 'for', the 'else' will execute. Here, we add 1 to 'i' to make i==n.

              j-=1
else:
              i+=1
              print('i= ',i,' ','j= ',j)


i= 10 
j= 0
>>>

read less
Answers 1 Comments
Dislike Bookmark

Looking for Python Training classes

Find best Python Training classes in your locality on UrbanPro.

FIND NOW

Answered 6 days ago IT Courses/Programming Languages/Python

What does "self" mean in python class? Why do we need it?

Santosh Kumar

Imagine a situation. You stay in a big home with family members cosy and comfortabily (Class in Programming world). Now here comes your American born cousin for a visit, He does not know what is where, How everything works in your home. Your cousin wants to perform some activites (Call some functions... read more

Imagine a situation.

You stay in a big home with family members cosy and comfortabily (Class in Programming world). Now here comes your American born cousin for a visit, He does not know what is where, How everything works in your home.

Your cousin wants to perform some activites  (Call some functions in Programming world).

1. Wants to go out in Car.

2. Wants to cook.

You are always with him and ensure all the necessity are there so that he can perform all these activites.

You always that guiding force that helps him.

YOU in this case is that "self" object.

Similarly in Python class, when a member function is called by an instance of that class.

Function which is being called has a reference to itself called SELF which can access the member variables and other member function through the SELF.

So every member function in class when called has invisible SELF object which points to current calling object.

In the same way You cousin is able to do all the activities with the help of you.

 

For more details and deeper python programming constructs, Join my classes.

Santosh

read less
Answers 1 Comments
Dislike Bookmark

About UrbanPro

UrbanPro.com helps you to connect with the best Python Training classes in India. Post Your Requirement today and get connected.

Overview

Questions 1.2 k

Lessons 56

Total Shares  

+ Follow 29,167 Followers

Top Contributors

Connect with Expert Tutors & Institutes for Python

x

Ask a Question

Please enter your Question

Please select a Tag

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 25 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 6.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more