Posts

Showing posts with the label Datatypes

Python Exercise 2 - "Faulty Calculator"

 Python Exercise 2 -  "Faulty Calculator" Q:     Design a calculator which will correctly solve all the problems except the following ones:    45 * 3 = 555, 56+9 = 77, 56/6 = 4   Your program should take operator & the two numbers as input from the user and then return the result. Solution: # Input Part Calculator_On = True print ( 'Welcome, Your Calculator is ready to serve you !' ) while (Calculator_On == True ): x = int ( input ( 'Please enter First number : ' )) y = int ( input ( 'Please enter Second number : ' )) operator = input ( 'Please Select Operator from these {*,/,+,-} : ' ) # Output Part if (operator == '*' ): if (x == 45 and y == 3 ): print ( 'Output : ' , 555 ) else : print ( 'Output : ' , x * y) elif (operator == '/' ): if (x == 56 and y == 6 ): print ( 'Output : ' , 4 ) else : prin...

Python Exercise 1--- Dictionary

 Python Exercise 1--- So, in this tutorial i.e. Python exercise 1 tutorial, what we have to do is, we have to create a dictionary, similar to the real-world dictionary. There is no limit to the definition you provide to any word as this exercise is just for your practice. The details and functionalities that are essential and must be present are: User will give a word as an input. Suppose that the word is present in your dictionary along with its definition or meaning. The program will print the meaning or definition of that word. For example: The user inputs the word : “programming” The output will be:  "the process of writing computer programs" Your main focus should be towards writing a neat and efficient code, using only the knowledge from our previously done tutorials. CODE--- #Exercise 1--- dic = { "A" : "Apple" , "B" : "Ball" , "C" : "Cat" , "D" : "Dog" } print ( "The required meaning ...

Python Tutorial 3---"Variables, Datatypes and Typecasting "

  Python Tutorial 3--- "Variables, Datatypes and Typecasting " This PROGRAM or TUTORIAL about Python's   "Variables, Datatypes and Typecasting " DOC Variable: A variable is a name given to any storage area or memory location in a program. In simple words, we can say that a variable is a container that contains some information, and whenever we need that information, we use the name of that container to access it. Let's create a variable: a = 34 # Variable storing an integer b = 23.2 # Variable storing real number Here  a  and  b  are variables, and we can use  a  to access 34 and  b  to access 23.2. We can also overwrite the values in  a  and  b Data Types in Python: Primarily there are following data types in Python. Integers (<class 'int'>): Used to store integers Floating point numbers (<class 'float'>): Used to store decimal or floating-point numbers Strings (<class 'str'>): Used to store st...