This page contains examples of basic concepts of Python programming; List Programs; String Programs; Dictionary Programs. Tuple Programs; Searching and Sorting Programs; Pattern Printing; Date-Time Programs; More Python ...
About Me
Get link
Facebook
X
Pinterest
Email
Other Apps
I write daily BLOGS about PYTHON with "Source Code"
Python Tutorial 29 --- "Enumerate Function" “ An enumerate is a built-in function that provides an index to data structure elements, making iterations through them easier and simpler.” In previous tutorials we have seen many methods that print items of different data structures onto the screen. For these kinds of operations, we need to have a for loop along with an iterator and an integer variable in which we have to increment every time the loop runs. Well, python provides us with a simple and easy solution to deal with certain situations by providing us with a built-in function known as “ enumerate function .” Using the enumerate function, we can summarize the code and make it easier and simpler to use. It is really important to know the concept of Enumerate function so that you can apply this concept to your code. Let us understand the working of enumerate function: What enumerate function does is, it assigns an index to every element or value in th...
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...
Python Exercise 4: "Number Guessing Game" Q: You have to build a "Number Guessing Game," in which a winning number is set to some integer value. The Program should take input from the user, and if the entered number is less than the winning number, a message should display that the number is smaller and vice versa. Instructions: 1. You are free to use anything we've studied till now. 2. The number of guesses should be limited, i.e (5 or 9). 3. Print the number of guesses left. 4. Print the number of guesses he took to win the game. 5. “Game Over” message should display if the number of guesses becomes equal to 0. You are advised to participate in solving this problem. This task helps you become a good problem solver and helps you accept the challenge and acquire new skills. Solution: print ( "Hii! Welcome, \n " , "This a number guessing game, " "made by Saswata \n " , "Let's Start \n " ) n...
Comments
Post a Comment