DEV Community

lordronjuyal
lordronjuyal

Posted on

day 04

date:- 23 May, 2024.

Randomization:- Computers are deterministic(we are not considering malfunctions etc). They will do what we ask them to do. They can't generate random outputs, even the AI. However, we can produce pseudo-random outputs from them by using large data and complex algorithms. Pseudo as we can still find pattern in the data but it will take significant time to reach that. To generate a random number in Python, we need a 'random module'.

Module:- Often Python projects get so big that it's not possible to maintain all code in one file. To solve this we create different files for different functionality. In a project, main.py is named as the main module. This file will execute first, and other modules will be called from here.
In Python, we are provided with many in-built modules. We save memory by including only those which are required in our program.
To include a python module, we will have to import it into the file where we want to use it.

List:- It's a data structure(way of arranging data). Its syntax is: list_name = [value1, value2]. Each value in it is arranged in order and provided a unique number called an index. The index starts from 0 and is assigned to the leftmost value. We add +1 as we move to the right.
To access the value from the list we write:
list_name[index_of_value] >>value

eg list=[a,b,c,d]
list[0] = a , list[2] = c , list[-1] = d
We can also lists inside a list. eg list=[[a,b,c],[1,2,3]]
list[0][1] = b

String:- like lists, in string, each character is also assigned a unique index.
eg string = "ABC" string[0] >>"A"

Functions I learned today:-

  1. random.randint(a,b) -This will generate a random number between a and b, including a & b.
  2. random.choice(list) -This will return a random value from the list.
  3. list.append(x) - This will add value x at the end of the list. list[-1] = x
  4. list.insert(i,x) - This will insert value x at index i, shift the previous value to right(will change its index also)

Program_for_today: Rock, paper and scissors

rock, paper, scissors game

Top comments (0)