Skip to main content

Command Palette

Search for a command to run...

Project-2 : Random Integer Number Guessing Game in Python

Updated
•3 min read•View as Markdown

Project -2

Link to see the code:

https://youtu.be/4N2FDLz9jrE

Problems that I encountered

  1. What is the difference in between randint(start,end) and randrange(start,end) function.

  2. How to use .split() function to take multiple inputs.

  3. How to take 'n' number of inputs in a single variable.

  4. how to convert a list of digit strings into integer list using for loop.

  5. Understanding how map function works.

  6. Separating the elements of the list and use them individually as a parameter in the randrange(start , element[0]) function

  7. How to store the randomly generated numbers into a list.

  8. How to use isinstance(int , list ) function and what it does.

  9. How to create an empty list.

  10. How to verify if the list has all the elements in it as the string digits using a loop.

Functions that I have used

  1. .split(): It is used take multiple inputs.

  2. map(arg1, arg2) : applies a function to each element of a collection, such as a list or set, and returns the results in a collection of the same type

  3. randint(start , end) : This function is used generate a random number in between those starting and including the end number .

  4. randrange(start , end) : This is similar to the randint but it doesn't include the end number only.

  5. .random_numbers = int(random_numbers) : this syntax changes the string into an actual integer , ex:- "23" --> 23.

  6. range(0,x) : similar to the randrange function it also generates random numbers.

  7. len() : It is used to con=unt the length of the the list according to the elements that are there in the list.

  8. import random : Python has a built-in module that you can use to make random numbers.

What I Learned

  1. .isdigit() function : it is used to verify whether the string is a digit or not.

  2.  values = list(map(int, values))  #Strings in alist to integers
    

    map(): this function maps the string into integers and store them in a list that is 'values' as earlier initialised

  3. How to take multiple inputs in a single variable that is a list without using a for, etc ... loop i.e., by using only the split() function , and create a list of strings stored in 'value' named list.

     values = str(input()).split()
      #While taking inputs it is storing thenm in the list format as a strings using .split() function
    
  4. I learned how to check if the list has all the string as an digit using a shorter syntax.

     print([x.isdigit() for x in values])
    
  5. Converting a string into a integer using syntax :

    random_number = int(random_number)

    i.e., "5" --> 5

  6. What is the use of .isinstance() function : It is used to check whether the input is of that class or not.

                 if isinstance(player_guess, str):
     #It checks if that varaiblke has the value that is of the string class.
    
  7. Create a list of randomly generated numbers.

     random_numbers=list(range(0,x))   
     #x is the end till which the random numbers will be generated. and will be stored in a list.
    
  8. Use of 'continue' : It is a keyword that directs the control to the upper nearest loop .

    'break' : It is used to get out the control out of the loops

  9. Use of 'and' 'or' : I used them in the trial and error programmes while making this programme , so I learned how to use them. T and T == T , T or F == T ,etc ... conditions.

  10. random.shuffle() : This function shuffles the list(random_numbers) of generated numbers. Syntax:

    ```python random.shuffle(random_numbers)

Output:
[0, 1, 2] list of random numbers generated [2, 1, 0] ```

  1. Creating a empty list --> syntax : list1 = []

More from this blog

Let see

16 posts